Visual Studio Development Bookmark and Share   
 index > Visual Basic Express Edition > handle event for a dynamically created object
 

handle event for a dynamically created object

hi guys... i wanna know how to handle an event for some object created during runtime..
i know how to write procedures for events at designtime.. mut say i created a timer during runtime, how do i handle its tick event...?

i did this..

▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Public Class MainClass
Shared t1 As Timer

Shared Sub main()
t1 = New Timer()
t1.Interval = 1000
t1.Enabled = True
t1.Start()
End Sub
Private Sub t1_tick(ByRef sender As System.Object, ByRef e As System.EventArgs) Handles t1.Tick
MsgBox("Its working..!!")
End Sub

End Class

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
but its giving error while compiling..
it says...

Error 1 Handles clause requires a WithEvents variable defined in the containing type or one of its base types. C:\Documents and Settings\Microsoft\My Documents\Visual Studio 2008\Projects\try\try\Class1.vb 2 91 try

at "handles t1.tick"

plz help me out...

theres nothing better than prime nos...!!
  • Edited bykool_Pragy Saturday, October 17, 2009 4:51 PMwrong spelling of event
  • Edited bykool_Pragy Saturday, October 17, 2009 4:53 PMformatted
  • Edited bykool_Pragy Saturday, October 17, 2009 4:55 PMformatted
  •  
kool_Pragy  Saturday, October 17, 2009 4:49 PM
The message is telling you to add the 'WithEvents' keyword after 'Shared" to your 't1' declaration.


Mark the best replies as answers. "Fooling computers since 1971."
  • Marked As Answer bykool_Pragy Saturday, October 17, 2009 6:20 PM
  •  
Rudedog2  Saturday, October 17, 2009 5:43 PM
The message is telling you to add the 'WithEvents' keyword after 'Shared" to your 't1' declaration.


Mark the best replies as answers. "Fooling computers since 1971."
  • Marked As Answer bykool_Pragy Saturday, October 17, 2009 6:20 PM
  •  
Rudedog2  Saturday, October 17, 2009 5:43 PM
The message is telling you to add the 'WithEvents' keyword after 'Shared" to your 't1' declaration.


Mark the best replies as answers. "Fooling computers since 1971."

hehe.. thnx... :-P

theres nothing better than prime nos...!!
kool_Pragy  Saturday, October 17, 2009 6:20 PM
For more information about the WithEvents keyword, read chapter "Event Keywords" of my SerialPort tutorial: http://www.innovatic.dk/knowledg/SerialCOM/SerialCOM.htm

Everything should be made as simple as possible, but not simpler. Any fool can write code that a computer can understand. Good programmers write code that humans understand.
Carsten Kanstrup  Sunday, October 18, 2009 9:18 AM

You can use google to search for other answers

Custom Search

More Threads

• How to use Microsoft Office Chart 11.0
• Make a simple keylogger....
• Help on editing a map
• How Can I Make This Work?
• Shuffling Items in a ListView
• printing for visual basic 2005 express edition
• difference between , and . please help
• How To Change PaperSize When Printing
• Class Library can't access System.Windows
• Graphics - Create, Save as jpeg/bmp/gif