0

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.

1
  • What about the note parameter? What data type it has? Commented Jun 8, 2012 at 5:08

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Beep is a class, all i'm doing is referencing it to generate a beep tone to play through the speakers. when i got rid of the line that was throwing the exception and changed it to "if tone is nothing the msgBox("tone is nothing.")." when i did that the exception moved to the line with the for each loop on it. same error, different line.
Well I guess trackWriter or noteArray are uninitialised then? Is this your code, or someone elses code you are editing?
Humm. It shouldn't be For each note in trackwriter.notearray, should it? (it would make more sense, since note would then be a parameter of the Beep.Tone call)
This is my code, and the beep class works fine everywhere else. i have another object running the beep class in the same form. And trackWriter i can access everywhere else in my project. It's initialsed in a form called "trackWriter" and i can access and use it from my main menu form with this exact same code outside of a background worker.
i got it working now, i had to re-initialise the variable before it was called for some reason, so i just copied trackWriter.noteArray into a second variable called "secondSounds" and referenced that instead. All is well now :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.