Jump to content

Recommended Posts

Posted

This doesn't seem to work on longer times, but I'm not sure what I did wrong. Anyone have suggestions?

$time = StringSplit(InputBox ("Time to run", "What hour would you like this script to run?  The current time is "& @HOUR & ":" & @MIN & ":" & @SEC, @HOUR & ":" & @MIN & ":" & @SEC), ":")
;MsgBox(4096, "Done", "Input is " & $time[1] & ":" & $time[2] & ":" & $time[3])
    $seconds = ($time[1] - @HOUR) * 3600 + ($time[2] - @MIN ) * 60 + ($time[3] - @SEC )
    if ($seconds < 0) Then 
  Return(0)
  MsgBox(4096, "Error", "Time already passed!")
    EndIf
    Sleep($seconds * 1000)
;MsgBox(4096, "Done", "Woke up at " & @HOUR & ":" & @MIN & ":" & @SEC)
Posted

Seems to work on my XP machine with no problems. What's the max time that you use? From the doc, max time for sleep() is 2147483647 milliseconds (24 days).

=MX+

Posted

This doesn't seem to work on longer times, but I'm not sure what I did wrong.  Anyone have suggestions?

$time = StringSplit(InputBox ("Time to run", "What hour would you like this script to run?  The current time is "& @HOUR & ":" & @MIN & ":" & @SEC, @HOUR & ":" & @MIN & ":" & @SEC), ":")
;MsgBox(4096, "Done", "Input is " & $time[1] & ":" & $time[2] & ":" & $time[3])
    $seconds = ($time[1] - @HOUR) * 3600 + ($time[2] - @MIN ) * 60 + ($time[3] - @SEC )
    if ($seconds < 0) Then 
  Return(0)
  MsgBox(4096, "Error", "Time already passed!")
    EndIf
    Sleep($seconds * 1000)
;MsgBox(4096, "Done", "Woke up at " & @HOUR & ":" & @MIN & ":" & @SEC)
I like the sleep idea instead of a continuous loop like I used to use

Are you converting to military time in your script or are you instructing your user to do so?

Rick

Posted

Instructing the user to do so. :-)

Well, I've tried it for ten minute increments, but when I set it to go off at 3 AM, and it was 1 AM, for some reason it just quit without doing anything (there's code that's supposed to execute after this bit). I'll test it out some more, I just wanted to see if I had done anything odd.

Posted (edited)

I was looking at the code and I was thinking:

Did you keep in mind that (for example):

15:00 minus 23:00 will be a negative number.

Never mind. As they say here in the Netherlands:

I didn't look further than the length of my nose.

The next line woke me up.

OK.

Some things I see:

- Why do you have this "Return(0)"

- And why is "Return(0)" not at the end of the "EndIf"

If you want to return a value and quit the current function.

Use this:

if ($seconds < 0) Then
 MsgBox(4096, "Error", "Time already passed!")
 Return 0
EndIf
Edited by SlimShady
Posted

Oh, yeah, I did switch the return and msgbox lines, thanks. But it's not the problem because that's just for error-checking, anyway. I don't have return after the EndIf because I want the rest of the script to run.

I'll just run it for an hour and see if anything odd happens again.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...