Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print an array with variable dimensions in VB

Status
Not open for further replies.

jackzhong

Structural
Joined
Mar 15, 2002
Messages
8
Location
US
Does anyone know how to print an array with variable dimensions in VB?

The following code won't do what I want, it outputs only one column, not rj (10 here) columns.

Open "debug.txt" For Output As #1
rm=10
rj=10
For i = 1 To rm
For j = 1 To rj
Print #1, my_array(i,j)
Next j
Next i
Close #1

What is the right code for my purpose? Thanks for your help.

Jack

 
'You need Something like this
dim fileNum as integer
'get the free file number
fileNum= Freefile
Open "debug.txt" For Output As fileNum
'allow for whatever the array has been dimensioned to
rm = ubound(my_array,1)
rj = ubound(my_array,2)
For i = 1 To rm
For j = 1 To rj
print fileNum, my_array(i,j), 'note the trailing commas
Next j
'new line
print fileNum, vbCrLf
Next i
Close #1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top