Hi Frank,
here’s a code snippet from a VB6 project. Records can be implemented as TYPES in VB6 and then used in arrays. This bit reads beach data from a datafile into a dynamic array that is resized as it reads so it works for files with different numbers of line.
Private Type beachRecord
name As String
rating As Integer
End Type
Private Sub ReadDataButton_Click()
Dim beachData() As beachRecord 'dynamic array, initially empty
Call readBeachData(beachData)
MsgBox ("The end")
End Sub
Private Sub readBeachData(ByRef dataArray() As beachRecord)
MsgBox ("Reading beach data")
Open "c:\temp\beachdata.csv" For Input As #1
Dim loopCounter As Integer
loopCounter = -1
Do While Not EOF(1) ' Loop until end of file
loopCounter = loopCounter + 1
ReDim Preserve dataArray(loopCounter)
Input #1, dataArray(loopCounter).name 'Read line into variables
Input #1, dataArray(loopCounter).rating
Loop
MsgBox (loopCounter & " records read from file")
MsgBox ("First entry : " & dataArray(0).name)
MsgBox ("Last entry : " & dataArray(loopCounter).name)
Close #FileHandle
End Sub
Project file attached.
Paul