Click here to Skip to main content
15,897,968 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
Hi,
I'm using vb.net windows form where I'm using a label for displaying a message. I also set a timer for that label (i.e.the display message should disappear within a period of time) with event Timer_Click() but it is not working properly here. Below is the code:
VB
Private Sub Timer1_Tick(ByVal sender As System.Object, By Val e As System.EventArgs) Handles TimerAddLoc.Tick

  If Date.Now - OpenedTime = New TimeSpan(0, 0, 10) Then
    lblErrorMsg.Text = ""
    TimerAddLoc.Enabled = False
  End If
End Sub

[in the top i declared under the Class name : Private OpenedTime As Date ]

Please help me.
Posted
Updated 25-Jan-11 22:36pm
v4
Comments
Sergey Alexandrovich Kryukov 26-Jan-11 0:13am    
Probably my mistake in this comment; it was different question, really unacceptable (Reported to administration as not a question.)
Sandeep Mewara 26-Jan-11 3:30am    
Thats a little too harsh. I totally agree, It's a badly formed question and incomplete.
But, we can see what OP is trying to do something and is unable to express properly.

OP gets my 'benefit of doubt' this time. :)
Sergey Alexandrovich Kryukov 26-Jan-11 14:13pm    
Sorry, may be I made a mistake in comment...
I really reported such thing, but there was not question at all; and not clue how to assume the question.
Sorry for trouble,
--SA
Sandeep Mewara 26-Jan-11 14:14pm    
Hey! It's fine. :)

Just looked to me a 'benefit of doubt' candidate, so shared with you.
JF2015 26-Jan-11 0:34am    
Unless you don't show us your code we can't help you but only guess and that's just a waste of time. So please, at least post a short snippet of what you wrote.

Timer_Click? Probably a typing mistake.

Look here for sample articles using Timer control in VB.NET:
Working with Timer Control in VB.NET[^]
Timers in VB.NET[^]

Next time onwards, do put in some more effort while forming the question. Just saying as 'Not working properly' is incomplete. Explaining the full behaviour and error if any would surely help.
 
Share this answer
 
Comments
IndrajitDasgupat 26-Jan-11 4:39am    
now I had given all the details please check
Sergey Alexandrovich Kryukov 26-Jan-11 11:25am    
Should answer all questions - a 5.
--SA
Hi,

try this:
VB
Private Sub Timer1_Tick(ByVal sender As System.Object, By Val e As System.EventArgs) Handles TimerAddLoc.Tick
  If DateTime.Now >= OpenedTime.AddSeconds(10) Then
    lblErrorMsg.Text = ""
    TimerAddLoc.Enabled = False
  End If
End Sub


What you of course need to do is: When you add the message to the label you need to set the OpenedTime, that means:
VB
OpenedTime = DateTime.Now
 
Share this answer
 
v2
Comments
IndrajitDasgupat 26-Jan-11 5:24am    
Thanks it is working now
Kschuler 26-Jan-11 10:44am    
If this answer fixed it, please accept the answer as correct so that others know that you have solved it and no longer need help. Thanks!
Espen Harlinn 26-Jan-11 7:43am    
5+ - nice and simple
Sergey Alexandrovich Kryukov 26-Jan-11 11:28am    
That's good - my 5.
May be some explanation of different times needed: Forms vs System.Times.
The timer in Forms is very inaccurate, not good enough for animation, for example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900