AutoHotkey Community

It is currently May 27th, 2012, 9:27 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: August 24th, 2006, 9:05 am 
Offline

Joined: April 26th, 2006, 4:10 am
Posts: 657
Location: New Mexico, USA
Code:
Sec =
Sec := (Sec*1000)
Min =
Min := (Min*60000)
Hour =
Hour := (Hour*3600000)
SMH := (Sec+Min+Hour)


Sorry if this has been posted before. I know some people must have thought it up already. If you want to sleep for 1 hour 32 minutes 5 seconds you would set it up like this:

Code:
Sec = 5
Sec := (Sec*1000)
Min = 32
Min := (Min*60000)
Hour = 1
Hour := (Hour*3600000)
SMH := (Sec+Min+Hour)

Sleep, %SMH%


Or of course the Sec, Min, Hour variable can be modified throughout the script.


Last edited by .AHK on September 23rd, 2006, 2:09 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2006, 2:17 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear .AHK, :)

It can be simplified with a function like:

Code:
Str2Sec(Time) {
StringSplit,F,Time,`:
Return ((F1*3600)+(F2*60)+F3)
}


Examples:

Code:
Sleep, Str2Sec("01:32:05")*1000

Code:
MsgBox, 64, MessageBox, Press Ok, % Str2Sec("01:32:05")


Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 23rd, 2006, 2:19 am 
Offline

Joined: April 26th, 2006, 4:10 am
Posts: 657
Location: New Mexico, USA
Now that I know the basics of functions I thought I would give this a try.

Code:
easyMS(h, m, s) {
     S := (S*1000)
    M := (M*60000)
  H := (H*3600000)
 SMH := (S+M+H)
Return SMH
}


To use it in a sleep I think it would be like this.

Code:
Sleep % easyMS(1, 35, 30)

Correct? Sleep for 1 hour, 35 minutes, 30 seconds.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 25th, 2006, 11:19 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
AHK's Manual, Sleep page wrote:
Delay The amount of time to pause (in milliseconds) between 0 and 2147483647 (24 days), which can be an expression.
No need to write Sleep % easyMS(...)

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 25th, 2006, 11:44 am 
Offline

Joined: April 26th, 2006, 4:10 am
Posts: 657
Location: New Mexico, USA
Quote:
No need to write Sleep % easyMS(...)

So a sleep automatically considers its parameter to be an expression without the %?

Code:
Sleep easyMS(1,2,5)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 25th, 2006, 11:58 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
.AHK wrote:
So a sleep automatically considers its parameter to be an expression without the %?

Yes because it accepts expressions. This is a simplified version of your function:
Code:
toMS(h, m = 0, s = 0, ms = 0) {
   return ms + (h * 3600 + m * 60 + s) * 1000
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2010, 11:32 pm 
Offline
User avatar

Joined: December 30th, 2009, 10:30 pm
Posts: 160
Location: Worcester, Massachusetts
You also don't need to escape the colon.

Code:
StringSplit, Time, Time, :

_________________
★★★ Email me at berban at aim full stop com ★★★


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2010, 12:43 pm 
Offline

Joined: February 19th, 2010, 8:07 pm
Posts: 615
Interesting how you can do the same thing in other ways...

I have always used the following to make time calculations:

Code:
sec  := 1000
min  := 60 * sec
hour := 60 * min

Sleep 5 * sec


All my scripts have those variables in case I want to use them for tooltips or Sleep timers, because it makes it very easy to read.

If I want to make specific calculations I would do the following:

Code:
sleep 1 * hour + 20 * min + 30 * sec ; 1h:20m:30sec


I dont need to use a function for that :D


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], nomissenrojb, Stigg and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group