-
Arrays in VB
Hello!
People have told me that the best way to do a controlled print of a recordset is to put the recordset data into a array, then read the array values into variables, and print selected information line by line in a txt file.
My problem is that i do not know how to get the data from the recordset into the 2D. array, and I do not know how to get array information into variable that i can do a print of... Do you have an example (with some code) of how this can be done?
Here is some of my code:
Dim rsNames As ADODB.Recordset
Dim sData As String
sData = ""
For Each fld In rsAddresses.Fields
sData = sData & fld.Name & ", "
Next
Do Until rsAddresses.EOF
sData = ""
For Each fld In rsAddresses.Fields
sData = sData & fld.Value & ", "
Next
rsAddresses.MoveNext
Print #1, sData; 'prints address
Loop
What i want is to get sData into an array, and then do a print from the array or something....
I'm thankful for all suggestions and tips.
-
Re: Arrays in VB
If u want both field values to be in the same 2D array;
Dim rsNames as ADODB.Recordset
Dim sData as string
Dim i as integer
Dim dataArray() as string
Redim dataArray(1,0) as string
sData = ""
for Each fld In rsAddresses.Fields
sData = sData & fld.Name & ", "
dataArray(0,i) = fld.Name
dataArray(1,i) = fld.Value
Redim Preserve dataArray(1,i+1) as string
i = i + 1
' I'm not familiar with print# ...
' but I think it can be used as follows
print #1, dataArray(0,i) ; 'prints address
print #1, dataArray(1,i) ;
next