Handles句にWithEvents変数を指定しませんでした。 プロシージャ宣言の最後にある Handles キーワードにより、 WithEvents キーワードを使用して宣言されたオブジェクト変数によって発生したイベントが処理されます。
エラー ID: BC30506
このエラーを解決するには
必要な WithEvents 変数を指定します。
例
次の例では、WithEvents キーワードがSystem.Timers.Timer インスタンスの定義で使用されていないため、Visual Basic によってコンパイラ エラー BC30506が生成されます。
Imports System.Timers
Module Module1
Private _timer1 As New Timer() With {.Interval = 1000, .Enabled = True}
Sub Main()
Console.WriteLine("Press any key to start the timer...")
Console.ReadKey()
_timer1.Start()
Console.ReadKey()
End Sub
Private Sub Timer1_Tick(sender As Object, args As EventArgs) Handles _timer1.Elapsed
Console.WriteLine("Press any key to terminate...")
End Sub
End Module
次の例では、 _timer1 変数が WithEvents キーワードで定義されているため、正常にコンパイルされます。
Imports System.Timers
Module Module1
Private WithEvents _timer1 As New Timer() With {.Interval = 1000}
Sub Main()
Console.WriteLine("Press any key to start the timer...")
Console.ReadKey()
_timer1.Start()
Console.ReadKey()
End Sub
Private Sub Timer1_Tick(sender As Object, args As EventArgs) Handles _timer1.Elapsed
Console.WriteLine("Press any key to terminate...")
End Sub
End Module
こちらも参照ください
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET