VB6 Array of Records

  • Frank Lagan

    We are still using VB6 and I wonder if anyone has an example of an array of records. I have mostly used python but have switched schools!


    Paul Gardner

    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
        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.


    Frank Lagan

    Hi paul. Thanks you very much for that. It works perfectly.


Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.