NullReferenceException Help?!

BlueOysterCult

Regular
Joined
Oct 3, 2003
Messages
84
Hello again my fellow Net forum users

I am wrestling with this Find Function and button. I am getting a Null Refernce error - I have tried every combination of things to no avail. I should point out that in the Autos tab I am getting a value (the artist I put in the FindBox.text) but it is red(?)

Function:

Code:
Public Function FindArtist(ByVal strArtistToFind As String) As Integer



        Dim i As New Integer
        'Dim ArtistIndex As Integer
        'loop through the array
        For i = 0 To CdArray.GetUpperBound(0)
            If CdArray(i).strArtist = strArtistToFind Then
                'we found the artist, return this index
                Return i
            End If
        Next

        'once this code is executed we know we didn't find an artist
        Return -1
    End Function

the button:
Code:
 Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
        Dim index As Integer = FindArtist(txtFindBox.Text)
        If index <> -1 Then
            txtArtist.Text = CdArray(index).strArtist
            txtTitle.Text = CdArray(index).strTitle
            txtYear.Text = CdArray(index).strYear
            txtCategory.Text = CdArray(index).strCategory


        Else
            MessageBox.Show("Artist not Found")
        End If


    End Sub
Thanks
Rob
 
Code:
 Public Sub LoadCDArray()

        Dim intCdCount As Integer

        'Read file into array
        Do Until EOF(gintCdFileNum)
            If intCdCount + 1 = Int(intCdCount + 1) Then
                ReDim Preserve CdArray(intCdCount + 1)

            End If

            ' Load the data in a loop with fields

            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)

    End Sub

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

End Structure

R
 
Back
Top