Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...