Friday, July 31, 2009

In visual basic 6, how do you populate a two dimensional array with a FOR loop?

I have a table with two columns: the first one has the ID numbers, and the second has the names of students. How do you populate an array with these two columns using the code at runtime and using a FOR loop?

In visual basic 6, how do you populate a two dimensional array with a FOR loop?
I don't use VB but here is some psuedo code using nested for statements.








for r = 0 to MyArray[].length


for c = 0 to MyArray[][].length


MyArray[r][c] = some value


end


end
Reply:Since I do program in VB6 maybe this will be a bit clear.





First dimension the double subscript variable like this


REDIM A$(3,5)


REM If I Haven't Forgotten That's 3 columns and 5 Rows


rem If I have forgotten then it's the reverse





FOR A=1 TO 3


FOR B=1 TO 5


A$(A,B)=STR$(CHR$(64)+B)


next B


NEXT A


'


for C=1 TO 3


FOR D=1 TO 5


Print A$(C,D)" ";:NEXT D:Print " "


next C


No comments:

Post a Comment