Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

time loop

Status
Not open for further replies.

jono261970

Programmer
Jun 28, 2002
182
GB
Hi,

Can somebody help me solve my problem. When the start time reaches say 07.00 it displays "enabled" and a msg box. I have now found out that it is going through this loop until the time reaches 07.01.

I set the time to hh:mm:ss and this solved the problem, however I use another form to set the start and stop times. I use a combo box to display all the hrs;

00:00 through to 24:00

I doesn`t look very good if I have to display the seconds as well.

00:00:00 through to 24:00:00


Private Sub Timer1_Timer()
Dim RAS As Integer
Dim wk(7)
Dim cnt As Integer
wk(1) = "Sunday"
wk(2) = "Monday"
wk(3) = "Tuesday"
wk(4) = "Wednesday"
wk(5) = "Thursday"
wk(6) = "Friday"
wk(7) = "Saturday"

cnt = Weekday(Now)
lblWkDay.Caption = wk(cnt)
LblTime.Caption = Time
Select Case Weekday(Now)
Case 2, 3, 4, 5, 6

If Format(Time, "hh:mm") = startime Then lblStatus.Caption = "ENABLED":msgbox "test"
If Format(Time, "hh:mm") = stoptime Then lblStatus.Caption = "DISABLED":msgbox "test"

Case Else
lblStatus.Caption = "DISABLED"


End Select
 
If Format(Time, &quot;hh:mm&quot;) = startime AND lblStatus.Caption <> &quot;ENABLED Then

lblStatus.Caption = &quot;ENABLED&quot;
msgbox &quot;test&quot;

elseIf Format(Time, &quot;hh:mm&quot;) = stoptime AND lblStatus.Caption <> &quot;DISABLED&quot; Then

lblStatus.Caption = &quot;DISABLED&quot;
msgbox &quot;test&quot;

Peter Meachem
peter @ accuflight.com

 
Try adding this &quot;Flag&quot; (varOnOff) into your code, it will make it so the sub only runs once

Private Sub Timer1_Timer()
Dim RAS As Integer
Dim wk(7)
Dim cnt As Integer
wk(1) = &quot;Sunday&quot;
wk(2) = &quot;Monday&quot;
wk(3) = &quot;Tuesday&quot;
wk(4) = &quot;Wednesday&quot;
wk(5) = &quot;Thursday&quot;
wk(6) = &quot;Friday&quot;
wk(7) = &quot;Saturday&quot;

cnt = Weekday(Now)
lblWkDay.Caption = wk(cnt)
LblTime.Caption = Time
Select Case Weekday(Now)
Case 2, 3, 4, 5, 6

If (Format(Time, &quot;hh:mm&quot;) = startime) and (varOnOff=0) Then lblStatus.Caption = &quot;ENABLED&quot;:msgbox &quot;test&quot;
varOnOff=1

If (Format(Time, &quot;hh:mm&quot;) = stoptime) and (varOnOff=1) Then lblStatus.Caption = &quot;DISABLED&quot;:msgbox &quot;test&quot;
varOnOff=0
Case Else
lblStatus.Caption = &quot;DISABLED&quot;


End Select
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top