Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

Timer suspension/resume

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
tvtech
Asked:
tvtech
  • 2
  • 2
  • 2
  • +6
1 Solution
 
andysalihCommented:
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
 
OtanaCommented:
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
 
glass_cookieCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
tvtechAuthor Commented:
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
 
BahnassCommented:
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
 
BGillhamCommented:
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
 
deightonCommented:
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
 
fparieCommented:
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
 
ArkCommented:
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
 
glass_cookieCommented:
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
 
BahnassCommented:
Hi deighton
         I think I suggested same solution !!!
         Nice 2 meet U
Bahnass
0
 
tvtechAuthor Commented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
  • 2
  • +6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now