Why isn't this code filling array?

BlueOysterCult

Regular
Joined
Oct 3, 2003
Messages
84
Hello All
The problem may lie elsewhere but I believe the array is not being filled - I get a “value cannot be null” error when I hit the "next" but on my form - the (obvious) next record to be displayed

Can someone see something?

Code:
 Private Sub LoadCDArray()

        Dim intCDCount As Integer

        ' Open the file
        Do Until EOF(gintCdFileNum)
            If intCDCount / 10 = Int(intCDCount / 10) Then
                ReDim Preserve CdArray(intCDCount + 10)

            End If


            ' Load the data in a loop

            Input(gintCdFileNum, CdArray(intCDCount).strArtist)
            Input(gintCdFileNum, CdArray(intCDCount).strTitle)
            Input(gintCdFileNum, CdArray(intCDCount).strYear)
            Input(gintCdFileNum, CdArray(intCDCount).strCategory)

            intCDCount += 1
        Loop
        ReDim Preserve CdArray(intCDCount - 1)
        '' Close the file
        'FileClose(gintCdFileNum)
    End Sub


End Class

Thanks
Rob
 
Which line of code causes the problem if you step through in a debugger?
Also you may find it easier to use the .Net file handling methods in System.IO rather than the VB6 FileOpen, Input, FileClose methods.
 
Thanks for your reply
Actually the Debugger is landing on the "Next" (and I assuming it will on the "Previous" button if it could get that far) button that calls the array
Code:
Private Sub MovePrevious(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                Handles mnuActionPrevious.Click, btnPrevious.Click
        If Not intCurrent = UBound(CdArray) Then

            intCurrent -= 1

        End If

        UpdateFormData()
    End Sub

It says UBound(CDArray) (that line anyway) = nothing or array can't be null or something


Thanks
ROb
 
I don't know - is trhis what you mean?
Like this? This is in my module:

Code:
  Structure CdType
        Dim strArtist As String
        Dim strTitle As String
        Dim strYear As String
        Dim strCategory As String

    End Structure
    Public CdArray() As CdType

#Region "Utility Procedures (non-UI)"

    Public Sub OpenFile()
        ' Get an available file number, store it in the global variable, and open the file.
        gintCdFileNum = FreeFile()
        FileOpen(gintCdFileNum, gstrCdFileName, OpenMode.Input)
    End Sub


    Public Sub GetNextRecord()

        'Get the next record, but only if we aren't already at the end of the file
        If Not EOF(gintCdFileNum) Then
            Input(gintCdFileNum, gstrArtist)
            Input(gintCdFileNum, gstrTitle)
            Input(gintCdFileNum, gshtYear)
            Input(gintCdFileNum, gstrCategory)


        End If

Yes I do have option strict on

Rob
 
Man,
I am sorry to take up so much of your time... nothing is happening still I am not going to the next record with the "next "button - but no errors that's a plus
R
 
thanks
Code:
Private Sub MoveNext(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles mnuActionNext.Click, btnNext.Click
        

        If Not intCurrent = UBound(CdArray) Then

            intCurrent += 1

        End If

        UpdateFormData()
    End Sub

    Private Sub MovePrevious(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                Handles mnuActionPrevious.Click, btnPrevious.Click
        If Not intCurrent = UBound(CdArray) Then

            intCurrent -= 1

        End If

        UpdateFormData()
    End Sub

GetNextRecord:

Code:
  Public Sub GetNextRecord()

        'Get the next record, but only if we aren't already at the end of the file
        If Not EOF(gintCdFileNum) Then
            Input(gintCdFileNum, gstrArtist)
            Input(gintCdFileNum, gstrTitle)
            Input(gintCdFileNum, gshtYear)
            Input(gintCdFileNum, gstrCategory)


        End If



    End Sub

LoadCDArray is after the next and previous - is the oder the problem?

R
 
Back
Top