0

I'm creating a script that will open a program , login , and do specific tasks . I created the login script with a variables adding and loopin through . The problem is with the program , sometimes it just gives you an error on connection or a network problem . What I need is IF the script gets the problem it'll reset it self and go through the account it got the error on , This is what I have so far and I just can't make it work

$t = 0
$n = "account"
$p = "password"

For $r = X To X
    Run("program")

    AutoITSetOption("MouseCoordMode", 0)
    AutoITSetOption("WinTitleMatchMode", 3)

    Do
        Sleep(1000)
        $t = $t + 1
    Until WinActive("program") Or $t = 15

    $t = 0

    Sleep(1500)
    Send("{TAB}")
    Sleep(100)
    Send("{TAB}")
    Sleep(100)
    Send("{Enter}")
    Sleep(100)
    Send($n & $r)
    Sleep(200)
    Send("{TAB}")
    Sleep(200)
    Send($p & $r)
    Sleep(100)
    Send("{Enter}")
    Sleep(5500)

    If $t > 14 Then
        $r = $r - 1
        Run(@ComSpec & " /c taskkill /F /im program.exe")

        Do
            Sleep(500)
            $t = $t + 1
        Until WinActive("Program - Update News") Or $t = 15

        $t = 0
        WinActivate("Program")
        Sleep(2000)
        MouseClick("Primary", 28, 12)
        Sleep(1000)
        MouseClick("Primary", 35, 125)
        Sleep(1000)
        MouseClick("Primary", 360, 175)
        Sleep(2000)
        Send("{ENTER}")
        Sleep(2500)

        Run(@ComSpec & " /c taskkill /F /im program.exe")
    ; EndIf
Next

Right now what it does is reruns the program without actually closing the error window

4
  • 1
    Where is the problem? Detect the error, react on it. That's it. By the way, your code isn't runnable. What is X ? Commented Mar 10, 2014 at 10:30
  • Problem is the error message isn't closing , even when i force it . I tried detect it with Until WinActive("Program - Error") Or $t = 15 and then force close it but the error message wont close and the script starts running without it closing and then the whole script just runs on the error message(i mean on the window). The X is the number of loops , say 100 To 150 , it'll run account100-account150 etc.. Commented Mar 10, 2014 at 10:54
  • Try to use Autoit Window Info to get the correct info from the window. Try to add WinSearchChildren with parameter 1 to search on child windows aswell. Use consolewrite to print the return values of your funtions to the console. Then you can see if the work. Try to use additional functions to really be sure you found the window. e.g. use If winexists then consolewrite (123) ... Commented Mar 10, 2014 at 12:19
  • I'm kind of new to this , can you be a little more specific in the placement of those commands? Commented Mar 10, 2014 at 13:38

1 Answer 1

1

Hopefully this will give you a better idea of how to create a script and fix your problem. It is commented to give you an understanding of the steps taken.

#include <msgboxconstants.au3>

Local $t = 0, $n = "account", $p = "password" ; $n & $p are your own data
Local $r = ["X", "X", "X"], $e, $msg, $w  ;$r is filled with your own data

AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("WinTitleMatchMode", 3)

HotKeySet("{ESC}", "Quit") ;If you want to exit the script, press the ESC key
Sender()  ;call the function to run

While 1
    If $e <> 0 Then   ;if @error is set to a non-zero variable, wait 1 sec (1000 millisec) and run again
        Sleep(1000)
        Sender()
    ElseIf $w = 0 Then  ;if msgbox value is 0 AND retry OR ignore has been pressed, wait 1 second and run again
        Sleep(1000)
        $w += 1
        Sender()
    EndIf
WEnd


Func Sender()   ;wrapped in function to make returning out of the function easier
    For $r = "X" To UBound($r)  ; for the first value in $r to the length of the array

        Run("program") 
        $e = @error  ;if Run sets @error then put @error and check the value with an if statement
        If $e <> 0 Then
            $msg = MsgBox(2, "ERROR", "error running program, exiting...")
            If $msg = $IDABORT Then  ;if we don't want to run the program again we abort
                Quit()
            ElseIf $msg = $IDRETRY Then ;if we want to retry then we hit retry
                Return
            ElseIf $msg = $IDIGNORE Then ;if we want to retry then we hit ignore as well
                Return ;go out of the function because we have recieved an error and want to restart the function
            EndIf
        EndIf
        SetError(0) ;sets @error to 0 so that we don't accidentally restart our program 
        Do
            Sleep(1000)
            $t += 1  ;add 1 to $t
            Sleep(1500)
            Send("{TAB}")
            Sleep(100)
            Send("{TAB}")
            Sleep(100)
            Send("{Enter}")
            Sleep(100)
            Send($n & $r)
            Sleep(200)
            Send("{TAB}")
            Sleep(200)
            Send($p & $r)
            Sleep(100)
            Send("{Enter}")
            Sleep(5500)
            If $t > 14 Then
                $r -= 1 ;minus 1 from $r
                Run(@ComSpec & " /c taskkill /F /im program.exe")
                $e = @error
                If $e <> 0 Then
                    $msg = MsgBox(2, "ERROR", "error running " & @ComSpec & " /c taskkill /F /im program.exe, Abort to Quit; Retry & Ignore to RETRY.")
                If $msg = $IDABORT Then
                    Quit()
                ElseIf $msg = $IDRETRY Then
                    Return
                ElseIf $msg = $IDIGNORE Then
                    Return
                EndIf
            EndIf
        EndIf
        SetError(0)
    Until WinActive("program") Or $t = 15

    $t = 0   ;set $t to 0

    Do
        Sleep(500)
        $t += 1
        $w = WinActivate("Program")
        If $w = 0 Then
            $msg = MsgBox(2, "ERROR", "error activating program, Abort to Quit; Retry & Ignore to RETRY.")
            If $msg = $IDABORT Then
                Quit()
            ElseIf $msg = $IDRETRY Then
                Return
            ElseIf $msg = $IDIGNORE Then
                Return
            EndIf
        EndIf
        $w += 1
        Sleep(2000)
        MouseClick("Primary", 28, 12)
        Sleep(1000)
        MouseClick("Primary", 35, 125)
        Sleep(1000)
        MouseClick("Primary", 360, 175)
        Sleep(2000)
        Send("{ENTER}")
        Sleep(2500)
        Run(@ComSpec & " /c taskkill /F /im program.exe")
        $e = @error
        If $e <> 0 Then
            $msg = MsgBox(2, "ERROR", "error running " & @ComSpec & " /c taskkill /F /im program.exe, Abort to Quit; Retry & Ignore to RETRY.")
            If $msg = $IDABORT Then
                Quit()
            ElseIf $msg = $IDRETRY Then
                Return
            ElseIf $msg = $IDIGNORE Then
                Return
            EndIf
        EndIf
        SetError(0)
    Until WinActive("Program - Update News") Or $t = 15

Next

EndFunc   ;==>Sender

Func Quit() ;will be called when we want to completely stop the script
    Exit
EndFunc   ;==>Quit
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.