BlueOysterCult Posted December 2, 2003 Posted December 2, 2003 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: 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: 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 Quote
*Experts* mutant Posted December 2, 2003 *Experts* Posted December 2, 2003 What line do you get the error on? Quote
BlueOysterCult Posted December 2, 2003 Author Posted December 2, 2003 For i = 0 To CdArray.GetUpperBound(0) R Quote
*Experts* mutant Posted December 2, 2003 *Experts* Posted December 2, 2003 Did you initialize your array? How do you declare it? Quote
BlueOysterCult Posted December 2, 2003 Author Posted December 2, 2003 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 Structure CdType Dim strArtist As String Dim strTitle As String Dim strYear As String Dim strCategory As String End Structure R Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.