RSS Forums RSS
Please support our VB.NET advertiser: Programming Forums
Views: 1613 | Replies: 4
Reply
Join Date: Mar 2006
Posts: 1
Reputation: mixthis is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mixthis mixthis is offline Offline
Newbie Poster

Newibe Needs Help

  #1  
Mar 16th, 2006
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2006
Posts: 12
Reputation: zmind is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
zmind zmind is offline Offline
Newbie Poster

Re: Newibe Needs Help

  #2  
Mar 17th, 2006
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
Reply With Quote  
Join Date: Apr 2006
Posts: 1
Reputation: dan18ca is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dan18ca dan18ca is offline Offline
Newbie Poster

Re: Newibe Needs Help

  #3  
Apr 5th, 2006
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.
Reply With Quote  
Join Date: Mar 2006
Posts: 219
Reputation: Lord Soth is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 3
Lord Soth's Avatar
Lord Soth Lord Soth is offline Offline
Posting Whiz in Training

Re: Newibe Needs Help

  #4  
Apr 6th, 2006
Hi,

Dim timer1 As Timer = new Timer

This will cure the null reference.

Loren Soth
Crimson K. Software _________________________________________________________________ Crimson K. Blog
Reply With Quote  
Join Date: Apr 2006
Posts: 18
Reputation: FPForum is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
FPForum FPForum is offline Offline
Newbie Poster

Re: Newibe Needs Help

  #5  
Apr 8th, 2006
did the timer enabled = true work? sounds like that was the issue to me..
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:44 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC