Sign in to follow this  
Followers 0
BigDaddyO

How to skip a function being run and move on to the next one?

7 posts in this topic

I have a large script with about 60 - 70 functions in it. if one of those functions locks up or gets stuck waiting for a window that is not showing up, I want to be able to skip that function and move on to the next one. I wanted to use a hotkey but I can't figure out how to exit one function from another. Is this possible?

The functions contain tests that are inside if statements. after the if statements the function cleans up the testing process and updates the Test data on the server. What I would really like is to simply exit the If statements in the current Function so it will still process the clean up portion of the function.

Hopefully someone can understand what I am asking.

I almost think I should put an overview of how my script works in my signature so whenever I ask another question I can just say please see signature for more info... hmm. I think I will do that.

Thanks,

Mike


Share this post


Link to post
Share on other sites



WinWait("WindowName", TimeToWait)

If Not WinExists("WindowName") Then NextFunction()

??


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Yes, I know, that is what my if statements inside these functions are doing mostly. waiting until a specific window opens, but the problem is that some windows I have to wait up to 10 minutes because they are SLOW web apps and I am running some tests on fairly slow comptuers.

So if I know the application won't load as if I see an error message... I would like to just hit say, F3 and the function would then close and it will move on to the next function "test"

Mike


Share this post


Link to post
Share on other sites

Dim $WindowErrorName = "What ever title the window throws an error"
Dim $CorrectWindow = "Window your waiting 10 minutes on"

Func WindowTestOne()
    $Timer = TimerInit()
    While TimerDiff($Timer) / 1000 * 60 < 10
        Sleep(100)
        If WinExists($WindowErrorName) Then SomeOtherFunction()
        If WinExists($CorrectWindow) Then ExitLoop
    WEnd
    If TimerDiff($Timer) / 1000 * 60 >= 10 And Not WinExists($CorrectWindow) Then SomeOtherFunction()
; The Commands I want to do If the right window was found.
EndFunc

I really don't understand the F3 thing, if you're wanting it to be fully auto, or you trying to do user interaction.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Yes, I know, that is what my if statements inside these functions are doing mostly. waiting until a specific window opens, but the problem is that some windows I have to wait up to 10 minutes because they are SLOW web apps and I am running some tests on fairly slow comptuers.

So if I know the application won't load as if I see an error message... I would like to just hit say, F3 and the function would then close and it will move on to the next function "test"

Mike

maybe try a variable that can be set via hotkey function to say whether a loop should keep running or not?

HotKeySet("{ESCAPE}","TESTFUNC")
$toggle = 1
Func TESTFUNC()
    If $toggle = 1 Then
        $toggle = 0
    Else
        $toggle = 1
    EndIf
EndFunc

testing()
$toggle = 1
testing2()
Func testing()
    while $toggle
        Sleep(100)
    WEnd
    MsgBox(0,"moving on","leaving function 1")
EndFunc
Func testing2()
    while $toggle
        Sleep(100)
    WEnd
    MsgBox(0,"moving on","leaving function 2")
EndFunc

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Or you could use cameronsdads...

I re-thought mine a bit, I kind of liked the timer idea... so here is a bit of a redo.

Dim $WindowErrorName = "What ever title the window throws an error"
Dim $CorrectWindow = "Window your waiting 10 minutes on"

Func WindowTestOne()
    Local $Timer = TimerInit()
    Local $Checked = 1
    While TimerDiff($Timer) / 1000 / 60 < 10
        Sleep(100)
        If WinExists($WindowErrorName) Then SomeOtherFunction()
        If WinExists($CorrectWindow) Then ExitLoop
        If TimerDiff($Timer) / 1000 / 60 >= 2 And $Checked = 1 Then
            $Checked = 2
            $iMsg = MsgBox(32 + 4, "Not Loaded", "The Window Has Not Loaded" & @CRLF & "Would You like to wait a little longer?")
            If $iMsg = 7 Then SomeOtherFunction()
        ElseIf TimerDiff($Timer) / 1000 / 60 >= 5 And $Checked = 2 Then
            $Checked = 0
            $iMsg = MsgBox(32 + 4, "Not Loaded", "The Window Has Not Loaded" & @CRLF & "Would You like to wait a little longer?")
            If $iMsg = 7 Then SomeOtherFunction()
        EndIf
    WEnd
    If TimerDiff($Timer) / 1000 / 60 >= 10 And Not WinExists($CorrectWindow) Then SomeOtherFunction()
; The Commands I want to do If the right window was found.
EndFunc

Giving the user the choice to wait or not.

Edit:

had * 60 should be / 60, didn't fix the first one if you use them, this is the correct one now.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thanks Guys,

By looking at your reply's I came up with the following.

Using this function I won't need to modify much of my script. I just replace the lines:

if winwaitactive("Program Name", "", 60) Then

with

if _WaitForIT("Program Name", "", 60) = 0 Then

Global $SkipIT = 0
Dim $loops = ""
HotKeySet("{F3}", "_SkipIT")

_TestApp001()


Func _TestApp001()
if _WaitForIT("Untitled - Notepad", "", 60) = 0 Then
    Send("The window is now active")
Else
    MsgBox(0, "Error", "Window did not show")
EndIf
EndFunc

Func _WaitForIT($Title, $text, $Wait)
    While Not WinActive($Title, $text)
        sleep(90)
        if $SkipIT = 1 then
            Global $SkipIT = 0
            Return 1
        EndIf
        if $loops >= $Wait then Return 1
        $loops = $loops + .1
    WEnd
    Return
EndFunc

Func _SkipIT()
    Global $SkipIT = 1
EndFunc

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  
Followers 0