PDA

View Full Version : VB printing an array to an ascii file


Jack
04-30-2002, 08:39 AM
Dim HoldArray(Beg To End) as double

In fortran
Write()(HoldArray(j),j=Beg,End)

In C/C++

For(j=Beg;j<=End;fprintf(~~~;%d,HoldArray(j++)));

How do I do this in VB using the PRINT statement?

The best I could do was this
Dim HoldLine As String
HoldLine = ""
For j = Beg To End
HoldLine = HoldLine & HoldArray(j) & " "
Next j

Print #1, HoldLine

There's gotta be a better way. I also found it interesting that this worked w/o having to convert HoldArray(j) into a string.

Thanks for your Help.

F**k Gates.

GadgetGeek
04-30-2002, 09:00 AM
For j = Beg To End
Print #1,HoldArray(j);
Next j
Print #1,

The ; keeps the print in the same line. If you want some sort of separator (like for a csv file) then
Print #1,HoldArray(j);",";
The extra print after the loop is sending the end of line (no semicolon)
If you need your HoldArray value formated in a specific format
Print #1,format(HoldArray(j),"0.00"); for example to print the number with 2 decimal places.

Jack
04-30-2002, 09:16 AM
Thanks.