Jump to content
Sign in to follow this  
bourny

Time Challange

Recommended Posts

bourny

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

Share this post


Link to post
Share on other sites
weaponx

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)

Share this post


Link to post
Share on other sites
bourny

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)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×