AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Easy Milliseconds (Second, Minute, Hour)

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
.AHK



Joined: 26 Apr 2006
Posts: 657
Location: New Mexico, USA

PostPosted: Thu Aug 24, 2006 8:05 am    Post subject: Easy Milliseconds (Second, Minute, Hour) Reply with quote

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 Sat Sep 23, 2006 1:09 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Thu Aug 24, 2006 1:17 pm    Post subject: Reply with quote

Dear .AHK, Smile

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, Smile
_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
.AHK



Joined: 26 Apr 2006
Posts: 657
Location: New Mexico, USA

PostPosted: Sat Sep 23, 2006 1:19 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
PhiLho



Joined: 27 Dec 2005
Posts: 6836
Location: France (near Paris)

PostPosted: Mon Sep 25, 2006 10:19 am    Post subject: Reply with quote

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(...)
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
.AHK



Joined: 26 Apr 2006
Posts: 657
Location: New Mexico, USA

PostPosted: Mon Sep 25, 2006 10:44 am    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
polyethene



Joined: 11 Aug 2004
Posts: 5248
Location: UK

PostPosted: Mon Sep 25, 2006 10:58 am    Post subject: Reply with quote

.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
}
Back to top
View user's profile Send private message Send e-mail Visit poster's website
berban



Joined: 30 Dec 2009
Posts: 159
Location: Worcester, Massachusetts

PostPosted: Sun Jun 20, 2010 10:32 pm    Post subject: Reply with quote

You also don't need to escape the colon.

Code:
StringSplit, Time, Time, :

_________________
★★★ Email me at berban at aim full stop com ★★★
Back to top
View user's profile Send private message Visit poster's website
RaptorX



Joined: 19 Feb 2010
Posts: 580

PostPosted: Mon Jun 21, 2010 11:43 am    Post subject: Reply with quote

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 Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group