Solved

Timer suspension/resume

Posted on 2001-07-30
12
425 Views
Last Modified: 2010-05-02
Greetings,

I actually asked this question a week ago and thought that the answer would work, however, I neglected to test it on a midnight rollover. Here is the deal ...

I populate 2 x ComboBoxes with all times from 6:00am, 6:30am etc through to 12:00am. I get the user to select a Suspend time and a Resume time. Let's say that the user wants a Timer to stop at 5:00pm and resume at 6:00am. Entering something like;

If Format$(Now,"hh:nn ampm") > Suspend and Format$(Now,"hh:nn ampm")<Resume then
     'Timer_Enabled=False
else
     'Timer_Enabled=True
Endif

That code will not work as it does not take the midnight jump into account and therefore, the Suspend time will not be greater. Can someone please point me in the right direction.

Thank you.

Regards,
    Tony
0
Comment
Question by:tvtech
  • 2
  • 2
  • 2
  • +6
12 Comments
 
LVL 3

Expert Comment

by:andysalih
Comment Utility
think your going to have to set a date in there somewhere

what you can do with a decision is

if time > suspend time and < resume time and date <> systemdate then

do what every

end if


cheers
andy
0
 
LVL 11

Expert Comment

by:Otana
Comment Utility
you can either store your date in a help variable and check on that too, when the date has changed store the new date, etc.

Or you can test on a datetime value, in which case you can always test on greater then.
0
 
LVL 8

Expert Comment

by:glass_cookie
Comment Utility
Hi!

How about doing something like specifying the number of hours to 'hang' or suspend instead?

With respect to your question, what you can do is something like this: (Remember to declare the sleep Api)

Take note of the indexes (form the combo box) of the suspend time and resume time.

The difference in listindexes would be Resume - Suspend.  Thus, you could:

Sleep 30*60*(Resume-Suspend)
'Do the actions :)


That's it!

glass cookie : )
0
 

Author Comment

by:tvtech
Comment Utility
Hi glass_cookie,

The Sleep API does not work for extended periods. Doing that would cause a "Not Responding" in the TaskList.

Regards,
   Tony
0
 
LVL 3

Expert Comment

by:Bahnass
Comment Utility
Hi tvtech

I hope like that may help
Note : the word Resume is a reserved word so I used REsumetime
   
    Dim SuspendTime As Date, ResumeTime As Date
    SuspendTime = Str(Date) & " " & combo1
    ResumeTime = Str(Date) & " " & combo2
    ResumeTime = IIf(ResumeTime < SuspendTime, 24 + ResumeTime, ResumeTime)
   
   
If Now > SuspendTime And Now < ResumeTime Then
    'Timer_Enabled=False
Else
    'Timer_Enabled=True
End If

0
 
LVL 3

Expert Comment

by:BGillham
Comment Utility
Here is a wait function that does not use the API.
Try it and let me know.

Public Sub Wait(HowManySecs As Integer)
    On Error GoTo LocalError
'   pause for HowManySecs seconds
    Dim EndWait
    EndWait = DateAdd("s", HowManySecs, Now)
    While Now < EndWait
        'Do nothing while waiting
    Wend
Exit Sub
LocalError:
End Sub
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 18

Expert Comment

by:deighton
Comment Utility
You need to take date into account, so best to convert to date type

Dim suspend As String
Dim resumex As String

Dim datSus As Date
Dim datRes As Date


suspend = "05:00 pm"
resumex = "06:00 am"

'work out where the time should fall

datSus = CDate(suspend) + Int(Now)
datRes = CDate(resumex) + Int(Now)

If datSus < Now Then datSus = datSus + 1
If datRes < Now Then datRes = datRes + 1


'*****

then when you do the comparisson

If Now > datSus And Now < datRes Then
    'Timer_Enabled=False
Else
    'Timer_Enabled=True
End If


0
 
LVL 1

Expert Comment

by:fparie
Comment Utility
this will assume a midnight rollover when resume < suspend.
i assume that is what you want to achieve.

if resume < suspend then
  If Format$(Now,"hh:nn ampm") > Suspend and Format$(Now,"hh:nn ampm")<Resume then
    'Timer_Enabled=True
  else
    'Timer_Enabled=False
  Endif
else
  If Format$(Now,"hh:nn ampm") > Suspend and Format$(Now,"hh:nn ampm")<Resume then
    'Timer_Enabled=False
  else
    'Timer_Enabled=True
  Endif
end if

some recommendations:
- use the date data type to compare times, this is more solid (will work regardless of regional settings...)
- use a checkbox so that users can indicate wether they will be crossing midnight. This allows you to check whether their input is correct.

good luck,
francois

0
 
LVL 27

Accepted Solution

by:
Ark earned 250 total points
Comment Utility
If Time > CDate(Suspend) And Time < DateAdd("d", Abs(CDate(sSuspend) > CDate(sResume)), CDate(sResume)) Then
    'Timer_Enabled=False
Else
    'Timer_Enabled=True
End If

Cheers
0
 
LVL 8

Expert Comment

by:glass_cookie
Comment Utility
Sorry...

If that causes a 'program is not responding' message, do this instead:

Take note of the indexes (form the combo box) of the suspend time and resume time.

The difference in listindexes would be Resume - Suspend.  

At the top:
Dim counttime as integer


In your event,

counttime = (Resume - Suspend)*30
Timer1.Enabled = True

In timer1,

If counttime = 0 Then
'Execute codes
Timer1.Enabled = False
Else
counttime = counttime - 1
End If

That's it!

glass cookie : )
0
 
LVL 3

Expert Comment

by:Bahnass
Comment Utility
Hi deighton
         I think I suggested same solution !!!
         Nice 2 meet U
Bahnass
0
 

Author Comment

by:tvtech
Comment Utility
Thanks Ark. Yours handles the situation exactly as I'd hoped.

Thank you to everyone else for your replies.

Kind regards,
    Tony
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now