a Timer in a class
-
Hi ! I'm using VB 6. I want to develop a class (.cls) in which I would like to instanciate a Timer (m_myTimer) and react to the event m_myTimer_Timer(). I know how to do that in a form (I put on my form the 'Timer' control), but I'm not able to do it in my class. I tried to do that :
Dim WithEvents m_myTimer As Timer Private Sub Class_Initialize() m_myTimer.Enabled = True m_myTimer.Interval = 2000 End Sub Private Sub m_myTimer_Timer() ' Handle event End Sub
but I get an error at line 'm_myTimer.Enabled= True'. I guess I have somewhere to do something like 'Set m_myTimer=whatever', but I can't figure out what to do. Thank you for your help ! Jerome -
Hi ! I'm using VB 6. I want to develop a class (.cls) in which I would like to instanciate a Timer (m_myTimer) and react to the event m_myTimer_Timer(). I know how to do that in a form (I put on my form the 'Timer' control), but I'm not able to do it in my class. I tried to do that :
Dim WithEvents m_myTimer As Timer Private Sub Class_Initialize() m_myTimer.Enabled = True m_myTimer.Interval = 2000 End Sub Private Sub m_myTimer_Timer() ' Handle event End Sub
but I get an error at line 'm_myTimer.Enabled= True'. I guess I have somewhere to do something like 'Set m_myTimer=whatever', but I can't figure out what to do. Thank you for your help ! JeromeTry changing this line:
Dim WithEvents m_myTimer As Timer
to this;Dim WithEvents m_myTimer As **New** Timer
-- Andrew.