Please support our VB.NET advertiser: Programming Forums
Views: 1613 | Replies: 4
![]() |
•
•
Join Date: Mar 2006
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
to all,
I'm a newbie to vb.net, currently I'm using vb.net ver. 2003, I'm trying to add a clock to my project. The following is what I have:
Dim timer1 As Timer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
timer1.Interval = 10000
Timer1.Start()
End Sub
Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
lblTimer1.Text = System.DateTime.Now
End Sub
End Class
when I try to comply this program I'm getting errors, which are: "An unhandled exception of type 'System.NullReferenceException' occurred in clk_test.exe"
Then there is a yellow arrow point to timer1.Interval = 1000.
Can someone pls. help......
thanks
mixthis
I'm a newbie to vb.net, currently I'm using vb.net ver. 2003, I'm trying to add a clock to my project. The following is what I have:
Dim timer1 As Timer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
timer1.Interval = 10000
Timer1.Start()
End Sub
Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
lblTimer1.Text = System.DateTime.Now
End Sub
End Class
when I try to comply this program I'm getting errors, which are: "An unhandled exception of type 'System.NullReferenceException' occurred in clk_test.exe"
Then there is a yellow arrow point to timer1.Interval = 1000.
Can someone pls. help......
thanks
mixthis
•
•
Join Date: Mar 2006
Posts: 12
Reputation:
Rep Power: 3
Solved Threads: 0
Try to use the Timer object from the toolbox instead of declaring your own Timer object. If you declare a Timer object you should also create an instante of that object. Your code does not make an instante of the Timer object.
I have tested your code on the form load event and when the timer tick event and it works OK but not able to simulate your problem. Probably you may just you
my suggestion on top
I have tested your code on the form load event and when the timer tick event and it works OK but not able to simulate your problem. Probably you may just you
my suggestion on top
•
•
Join Date: Apr 2006
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Originally Posted by mixthis
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
timer1.Interval = 10000
Timer1.Start()
End Sub
As far as I know, you also need to use "Timer1.Enabled = True" to start the timer, and "Timer1.Enabled = False" to turn the timer off. You also probably want a timer interval of 1000 to update every second as opposed to every 10 seconds, this is easier to set up in the object properties as opposed to in a Form1_Load event.
Hi,
Dim timer1 As Timer = new Timer
This will cure the null reference.
Loren Soth
Dim timer1 As Timer = new Timer
This will cure the null reference.
Loren Soth
Crimson K. Software _________________________________________________________________ Crimson K. Blog
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode