bourny Posted May 1, 2008 Share Posted May 1, 2008 I need some assistance witrh the following. My script currently Sleeps for 5 minutes at a point in the script if chosen by the user. This is hard coded in the script as a default time of 5 minutes. I am extending the functionality to allow the command line -SleepTime:#.## (Example SleepTime:0.45 for 45 mins sleep OR SleepTime:1.20 for 1 hour 20 mins sleep) I can easily get this into a variable from the command line -SleepTime but cannot accuratly get the script to understand the 1.20 / 0.45 etc into a time autoIt understands My script at the moment will do a Sleep(300000) for 5 mins so I know I need to do a 60 / 60000 for the first part of the hours if 1 or 120 / 60000 for 2 hours etc. where I get stuck is if the user puts something like SleepTime:1.85 Which should be 2h 25 mins but how do I get autoIt to accuratly work this out into a time it can understand - I would like to cater for this sort of incorrect input I will be putting a 2 character limitation on the right and a max of 5 on the left part of the sleepTime:1.85 Hope I have explained this well enough to understand Any help appreciated Link to comment Share on other sites More sharing options...
Bert Posted May 1, 2008 Share Posted May 1, 2008 Use a dropdown box with only certain choices. That way you can hard code what each choice is, and avoid the headache The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
monoceres Posted May 1, 2008 Share Posted May 1, 2008 Maybe? $input=InputBox("Get sleep time","How long to sleep (x.x)") $array=StringSplit($input,".") If StringLen($array[1])>2 Or StringLen($array[2])>5 Then MsgBox(16,"Error","To many chars!") Exit EndIf Sleep(($array[1]*3600*1000)+($array[2]*60*1000)) Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
weaponx Posted May 1, 2008 Share Posted May 1, 2008 You should probably allow for HH:MM:SS. Or since you are already using the colon to parse the command line, seperate with something else. $split = StringSplit("1.85.00", ".") ;If at least hour is present If $split[0] Then $HH = $split[1] ;If at least minutes are present If $split[0] > 1 Then $MM = $split[2] ;If seconds are present If $split[0] > 2 Then $SS = $split[3] EndIf EndIf EndIf ;Convert hours to minutes $MM += $HH*60 ;Convert minutes to seconds $SS += $MM*60 ;Convert seconds to milliseconds $MS = $SS*1000 ConsoleWrite($MS) Link to comment Share on other sites More sharing options...
bourny Posted May 1, 2008 Author Share Posted May 1, 2008 Thanks for the replies..... The code from weaponx looks the closest to what I am trying to do. I dont really want to use input boxes or drop downs as I am using a command line varaible to get the input .... Thanks again You should probably allow for HH:MM:SS. Or since you are already using the colon to parse the command line, seperate with something else. $split = StringSplit("1.85.00", ".") ;If at least hour is present If $split[0] Then $HH = $split[1] ;If at least minutes are present If $split[0] > 1 Then $MM = $split[2] ;If seconds are present If $split[0] > 2 Then $SS = $split[3] EndIf EndIf EndIf ;Convert hours to minutes $MM += $HH*60 ;Convert minutes to seconds $SS += $MM*60 ;Convert seconds to milliseconds $MS = $SS*1000 ConsoleWrite($MS) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now