Object reference not set to an instance of an object. unknown why i'm getting this error

I'm having some trouble with a program i'm making, everytime i try to run the form that runs this code:

Private Sub customDuffer_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles customDuffer.DoWork
    While (Me.Visible = True)
        For Each tone In trackWriter.noteArray
            If switch = True Then
                Beep.tone(1000, note, 240)
            End If
        Next tone
    End While

Beep.tone(1000, note, 240)<< this is the line that throws the exception. i have exactly the same code on my main form and it runs perfectly everywhere else, only in the form where it is supposed to be run do i get an exception.

Note array is public and i can access it fine from everywhere else, and the custom class beep works fine. any help would be greatly appreciated.

Upvotes: 0

Views: 153

Answers (1)

SSS
SSS

Reputation: 5393

Either Beep or note variables must be uninitialised. Add some debug code:

If switch = True Then
  If Beep is Nothing then MsgBox ("Beep is nothing!")
  If note is Nothing then MsgBox ("note is nothing!")
  Beep.tone(1000, note, 240)
End If

run it, see which message pops up. Then work out where it should be initialised.

If neither message pops up then there is an uninitialised variable bug in the Beep.tone() method.

Upvotes: 1

Related Questions