Jump to content

Recommended Posts

Posted

Hi,

I want run a program in assign time.

like open IE visit a URL, if in 3000 second open the URL is not finished.

open a messagesbox show messages "error".

how can I control the assign time ?

Thanks

Posted

I suggest reading the help file

Check out the following topics:

@HOUR

@SEC

@MIN

I red this :

#include <Date.au3>

Global $Sec, $Min, $Hour, $Time

; 计算当前时间

$StartTicks = _TimeToTicks(@HOUR,@MIN,@SEC)

; 计算 45 分钟后的时间

$EndTicks = $StartTicks + 45 * 60 * 1000

_TicksToTime($EndTicks,$Hour,$Min,$Sec)

MsgBox(262144,'' , 'New Time:' & $Hour & ":" & $Min & ":" & $Sec)

above . I thik "$Sec, $Min, $Hour, $Time" is not for me question

Posted

I think the more appropriate way would be to use the IE udf:

#include <IE.au3>
$ieObj = _IECreate("www.google.com", 0, 1, 0)

_IELoadWait($ieObj, 0, 3000)

If @error Then
    MsgBox(0, "Error", "The page was not loaded in 3 seconds, exiting")
    Exit
EndIf
:)

thank you very much!

but you answer is only for IE.

how about for program?

(like this ? Run("Notepad.exe", "", @SW_MAXIMIZE,3000) ??? hehe I not find this in help file....)

Posted (edited)

Well I guess it depends on what you want to call "Loaded" in that case, you could just check if the window is visible:

Opt("WinTitleMatchMode", 4)

Run("notepad")

$LoadTime = _LoadWaitApp("[CLASS:Notepad]", "", 3000)
If @error Then
    MsgBox(0, "Error", "The program was not loaded in 3 seconds, exiting")
    Exit
EndIf

MsgBox(0, "Program loaded", "Program was loaded in " & Round($LoadTime/1000, 2) & " seconds")

Func _LoadWaitApp($s_wTitle, $s_wText = "", $i_TimeOut = 15000)
    
    Local $i_tHandle = TimerInit(), $i_tDiff = 0
    
    Do
        Sleep(250)
        $i_tDiff = TimerDiff($i_tHandle)
    Until BitAND(WinGetState($s_wTitle, $s_wText), 2) Or $i_tDiff > $i_TimeOut ; Wait untill the window is visible, or the timer runs out
    
    If TimerDiff($i_tHandle) > $i_TimeOut Then
        SetError(1)
        Return 0 ; Timeout was hit
    Else
        SetError(0)
        Return $i_tDiff ; Returns the time it took for the app to launch
    EndIf   
    
EndFunc
Edited by FreeFry
Posted

YES!

Grate!,thank you very much!

I will learn you post script :)

thanks

Well I guess it depends on what you want to call "Loaded" in that case, you could just check if the window is visible:

Opt("WinTitleMatchMode", 4)

Run("notepad")

$LoadTime = _LoadWaitApp("[CLASS:Notepad]", "", 3000)
If @error Then
    MsgBox(0, "Error", "The program was not loaded in 3 seconds, exiting")
    Exit
EndIf

MsgBox(0, "Program loaded", "Program was loaded in " & Round($LoadTime/1000, 2) & " seconds")

Func _LoadWaitApp($s_wTitle, $s_wText = "", $i_TimeOut = 15000)
    
    Local $i_tHandle = TimerInit(), $i_tDiff = 0
    
    Do
        Sleep(250)
        $i_tDiff = TimerDiff($i_tHandle)
    Until BitAND(WinGetState($s_wTitle, $s_wText), 2) Or $i_tDiff > $i_TimeOut ; Wait untill the window is visible, or the timer runs out
    
    If TimerDiff($i_tHandle) > $i_TimeOut Then
        SetError(1)
        Return 0 ; Timeout was hit
    Else
        SetError(0)
        Return $i_tDiff ; Returns the time it took for the app to launch
    EndIf   
    
EndFunc

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...