Array is very helpful when you need to save some parameters temporary. In this post, i just want to write the sintax in vb 6.
Declare Array - same with other language declaration variables
Public arr2D() As String
Fill Array - I get data from database, then while looping data, it placed in array.
ReDim Preserve arr2D(DataCount - 1, 2) meaning : because array index from 0, then size array dataCount - 1 and 2 is array size that i want to save (it depends on requirement)
For i = 0 To DataCount - 1
ReDim Preserve arr2D(DataCount - 1, 2)
arr2D(i, 0) = i
arr2D(i, 1) = Trim(rs!id)
arr2D(i, 2) = Trim(rs!name)
rs.MoveNext
Next
For example Datacount has 3 items, then :
- please correct me if i am wrong, but it works for me.
View Array - after fill array success, then you have to get data array to save or to preview in program.
If (Not arr2D()) = -1 Then ----------- to check if array is empty
else
For i = 0 To UBound(arr2D)
msgbox arr2D(i,0)
msgbox arr2D(i,1)
msgbox arr2D(i,2)
Next i
End If
It usually looping in looping, but because I know the size only 3 (2 size in array) , then I just loop 1 times.
Declare Array - same with other language declaration variables
Public arr2D() As String
Fill Array - I get data from database, then while looping data, it placed in array.
ReDim Preserve arr2D(DataCount - 1, 2) meaning : because array index from 0, then size array dataCount - 1 and 2 is array size that i want to save (it depends on requirement)
For i = 0 To DataCount - 1
ReDim Preserve arr2D(DataCount - 1, 2)
arr2D(i, 0) = i
arr2D(i, 1) = Trim(rs!id)
arr2D(i, 2) = Trim(rs!name)
rs.MoveNext
Next
For example Datacount has 3 items, then :
2
|
- please correct me if i am wrong, but it works for me.
View Array - after fill array success, then you have to get data array to save or to preview in program.
If (Not arr2D()) = -1 Then ----------- to check if array is empty
else
For i = 0 To UBound(arr2D)
msgbox arr2D(i,0)
msgbox arr2D(i,1)
msgbox arr2D(i,2)
Next i
End If
It usually looping in looping, but because I know the size only 3 (2 size in array) , then I just loop 1 times.