Link to home
Start Free TrialLog in
Avatar of Helix
Helix

asked on

Timer function

Hi everyone, I have a time fuction which displayed the time on my form, what i want to do is when the time displays 9:00 the caption of a label will change

I have tried any different things to do this but with no such luck, ive tried doing:

If Time = "9:00:00" Then
Msgbox = "bla bla bla"

and

If Time = Format("hh....etc etc
msgbox = "bla bla bla"

but nothing happens. ive also tried

If lblTime.Caption = "9:00:00" Then
Msgbox = "bla bla bla"

What am i doing wrong?

Thanks


Avatar of eric0213
eric0213

Show us the line you use to set the label caption?
Avatar of Helix

ASKER

eh?
This works...

Private Sub Timer1_Timer()
    Dim x As Date
    x = Time
   
    If FormatDateTime(x, vbShortTime) = "09:00" Then MsgBox "hi helix"
End Sub

You could also do a StrComp
MsgBox StrComp(FormatDateTime(x, vbShortTime), "09:00", vbTextCompare)

Don't know if that helps any....
It sounds like you are not running this code in a loop. To do what eric0213 suggested, drop a Timer control on your form, set it to enabled with an interval of 500, double click on it, then paste his code in the function.

HTH,

Zaphod.
Avatar of Helix

ASKER

thanks eric0213 that was great, thanks for the help :)

soz i havn't replied in a while, school work :(

one last problem remains though, a message box will keep appearing saying "hi helix", is there a way to only come up once?
ASKER CERTIFIED SOLUTION
Avatar of eric0213
eric0213

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Helix

ASKER

Thanks a lot, that worked perfectly :)