Timer - Error 1 Handles clause requires a WithEvents (Even on MSDN example code)

ironfistchamp

Active member
Joined
Dec 9, 2005
Messages
29
Programming Experience
Beginner
I am creating a small program that uses a timer to check a statement every 5 seconds and calls a sub if it is true.

I have that bit working fine it is just that I get the error message "Error 1 Handles clause requires a WithEvents variable defined in the containing type or one of its base types. " when I try to debug it. The timer is called timer1 and I got the code from the MSDN support database.

When I tried to create the program they had (absolutely identically) I have the same error message.

"Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick "

It is on that line of code and the underlined bit is the Timer1 from Timer1.Tick at the end.

Can someone help be sort this please.

Thanks very much

Ironfistchamp
 
Did you add a timer control to the form?
In Designer View double click a timer from the sidebar menu, it will automatically name itself 'timer1' if there is not already one named so.
This will also add 'withevents' processing statement to the variable, meaning that the form will look for events for the (timer) object.
In addition to the component setup, it will look like this:
Friend WithEvents Timer1 As System.Windows.Forms.Timer
 
Back
Top