Page 1 of 1

Get second before an execution

PostPosted: Tue Nov 15, 2011 8:36 am
by Alex
Hi,

I try to make a timer wait before the excecution, but I have a bug to calculate how many second it has to wait before starting:

Code: Select all
DateToNum "[DayNum]/[MonthNum]/[Year]" "d/m/y" "[OpenDateNum]"

StrReplace "16-11-2011" "-" "/" "[DateSTART]" ""
DateToNum "![DateSTART]" "d/m/y/" "[ToDayDateNum]"

StrParse "14:00" ":" "[T]" "[Temp]"
Math "([T1]*3600)+([T2]*60)" "0" "[ET1]"

StrParse "[Time24]" ":" "[T]" "[Temp]"
Math "([T1]*3600)+([T2]*60)" "0" "[ET2]"

Math "([OpenDateNum]*86400)+[ET1]" "0" "[OpenDateSec]"
Math "([TodayDateNum]*86400)+[ET2]" "0" "[ToDayDateSec]"
Math "([OpenDateSec]-[ToDayDateSec])*1000" "0" "[ElapsedSec]"


For example, I would like to know how many second we have to wait before the 16-11-2011 at 14:00 if now it is 15-11-2011 and 15:45.

Thanks


Alex

PostPosted: Tue Nov 15, 2011 11:41 am
by Neosoft Support
I don't think calculating the number of milliseconds between to dates/times is the most efficient method of doing what you want to do. Instead I would recommend you take a look at the following example pub:

http://www.neosoftware.com/neobook/modules/pubs/singlefile.php?cid=10&lid=129

PostPosted: Tue Nov 15, 2011 2:03 pm
by Alex
Hi,

Thank you for your answer.

This is interesting, but for my program, this will be a little complicate. I need to know how many seconds before a specified day and time like the code I wrote, but this doesn't work.

Any idea?

Thanks


Alex

PostPosted: Wed Nov 16, 2011 11:50 am
by Neosoft Support
Maybe you can adapt this script:

Code: Select all
.Convert time1 to seconds since midnight
SubStr "[Time1]" "1" "2" "[H]"
SubStr "[Time1]" "4" "2" "[M]"
SubStr "[Time1]" "7" "2" "[S]"
Math "([H]*3600)+([M]*60)+[S]" "0" "[T1]"

.Convert time2 to seconds since midnight
SubStr "[Time2]" "1" "2" "[H]"
SubStr "[Time2]" "4" "2" "[M]"
SubStr "[Time2]" "7" "2" "[S]"
Math "([H]*3600)+([M]*60)+[S]" "0" "[T2]"

.Convert date1 to days
DateToNum "[Date1]" "m/d/y" "[D1]"

.Convert date2 to days
DateToNum "[Date2]" "m/d/y" "[D2]"

.subtract date2 from date1 and convert to seconds
Math "([D2]-[D1])*86400" "0" "[ElapsedDaysAsSeconds]"

.subtract time2 from time1
Math "[T2]-[T1]" "0" "[ElapsedSeconds]"

.combine elapsed days as seconds and seconds
Math "[ElapsedDaysAsSeconds]+[ElapsedSeconds]" "0" "[ElapsedTime]"

.display the results
AlertBox "Result" "Elapsed time is: [ElapsedTime] seconds"

PostPosted: Wed Nov 16, 2011 12:34 pm
by datadon
The second before an execution...

"I'm innocent! I tell you I'm innocent!"


sorry, had to say it.

PostPosted: Wed Nov 16, 2011 12:54 pm
by Gaev
Don:
"I'm innocent! I tell you I'm innocent!"

More like "I'm innocent! I tell you I'm inno ...."

PostPosted: Wed Nov 16, 2011 1:02 pm
by datadon
Yep, last words cut off in mid sentence.

PostPosted: Thu Nov 17, 2011 3:36 am
by Alex
Hi,

Excellent, works fine, thanks !


Alex