Solved

Timer suspension/resume

Posted on 2001-07-30
12
426 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
ID: 6333244
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
ID: 6333248
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
ID: 6333264
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
ID: 6333346
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
ID: 6333517
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
ID: 6333564
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 18

Expert Comment

by:deighton
ID: 6333596
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
ID: 6333618
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
ID: 6339259
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
ID: 6340190
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
ID: 6340852
Hi deighton
         I think I suggested same solution !!!
         Nice 2 meet U
Bahnass
0
 

Author Comment

by:tvtech
ID: 6347973
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

863 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

23 Experts available now in Live!

Get 1:1 Help Now