Source language: Translate to:

Get second before an execution

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Get second before an execution

Postby Alex » Tue Nov 15, 2011 8:36 am

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
Alex
 
Posts: 745
Joined: Sat Mar 04, 2006 4:53 am

Postby Neosoft Support » Tue Nov 15, 2011 11:41 am

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
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby Alex » Tue Nov 15, 2011 2:03 pm

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
Alex
 
Posts: 745
Joined: Sat Mar 04, 2006 4:53 am

Postby Neosoft Support » Wed Nov 16, 2011 11:50 am

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"
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby datadon » Wed Nov 16, 2011 12:34 pm

The second before an execution...

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


sorry, had to say it.
Don

'If you want to get a brontosaurus from 'a' to 'b' then you ride the dinosaur - you don't carry it!'
User avatar
datadon
 
Posts: 389
Joined: Sun Apr 03, 2005 7:55 pm
Location: Lorena Texas

Postby Gaev » Wed Nov 16, 2011 12:54 pm

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

More like "I'm innocent! I tell you I'm inno ...."
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby datadon » Wed Nov 16, 2011 1:02 pm

Yep, last words cut off in mid sentence.
Don

'If you want to get a brontosaurus from 'a' to 'b' then you ride the dinosaur - you don't carry it!'
User avatar
datadon
 
Posts: 389
Joined: Sun Apr 03, 2005 7:55 pm
Location: Lorena Texas

Postby Alex » Thu Nov 17, 2011 3:36 am

Hi,

Excellent, works fine, thanks !


Alex
Alex
 
Posts: 745
Joined: Sat Mar 04, 2006 4:53 am


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest