0

每次我尝试运行运行此代码的表单时,我正在制作的程序遇到问题:

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)<< 这是引发异常的行。我的主表单上有完全相同的代码,它在其他任何地方都可以完美运行,只有在应该运行的表单中我才会遇到异常。

注意数组是公共的,我可以从其他任何地方正常访问它,并且自定义类哔声工作正常。任何帮助将不胜感激。

4

1 回答 1

1

Beep 或 note 变量必须未初始化。添加一些调试代码:

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

运行它,看看弹出哪个消息。然后找出应该初始化的位置。

如果没有消息弹出,则 Beep.tone() 方法中存在未初始化的变量错误。

于 2012-06-08T05:13:50.220 回答