Timppa

Continue the current for loop if interrupted by AdlibRegister

2 posts in this topic

Hello!

I have a function that checks for either completed update or update that had errors.

This is one part of function (rest doesn't matter because they don't affect on anything, just variables)

for $i = 0 To $RepeatNumber Step + 1
      ToolTip("Not ready yet")
      Sleep(1000)
      CheckScreen() ;Returns $Confirm variable
      If $Confirm = 1 Then
         ToolTip("The update is now completed!")
         Sleep(1000)
         AdlibRegister("InformUser()")
      EndIf
   Next
      Sleep(200)
      for $i = 0 To $RepeatNumber Step + 1
         ToolTip("Finding for errors")
         Sleep(1000)
         $FindErrors = 1
         CheckScreen()
         If $Confirm = 1 Then
            AdlibRegister("InformUser()")
         EndIf
      Next
         ToolTip("Nothing found yet")
         Sleep(1000)
         $Repeat = 1

 

So what I want to do now is that it checks first for completed update, if there is certain button (that the update succeeded), it will then do whatever it needs to.

Then if after $i == $RepeatNumber (Input integer to define how many times should it be checked), go check for errors for $RepeatNumber times. If there still is no succeeded update or errors on update, it runs the same Function again as long as either is found.

Now what my script does is that if there is succeeded update, it will just restart the function. For example my function finds succeeded update after the $i = 5, then it does the function that it will call from AdlibRegister and then continue checking UNTIL $i = $RepeatNumber, there is many of them to be checked. Then after that go to error section.

 

I thought it would work with the AdlibRegister but it just starts it over again. Is there any other methods to do this?

 

Thanks in advance!

Share this post


Link to post
Share on other sites



Timppa,

That looks a very confused snippet. Why are you using Adlib to announce a single event? Why not announce it directly?

From what you have described (rather vaguely), I think this will do what you want:

Global $bConfirm = False, $bFindErrors = False

Local $iRepeatNumber = 5, $iSuccess = 0, $iError = 0

While 1

    For $i = 1 To $iRepeatNumber ; No need for Step if it is +1

        Sleep(100)
        ; Look for success
        CheckScreen() ; Sets $bConfirm variable
        ; Depending on setting
        If $bConfirm Then
            Sleep(100)
            InformUser($i, 1) ; Index and mode = success
            ; Clear flag
            $bConfirm = False
            ; Increase count
            $iSuccess += 1
        EndIf



        ; Look for failure
        CheckScreen() ; Sets $bConfirm variable
        If $bConfirm Then
            Sleep(100)
            InformUser($i, 0) ; Index and mode = failure
            $bConfirm = False
            $iError += 1
        EndIf



    Next

    ; Check if all succeeded or failed
    If $iSuccess + $iError = $iRepeatNumber Then
        ; If so, then exit the loop
        ExitLoop

    EndIf

    ; If not then reloop

    ConsoleWrite("Restarting loop" & @CRLF)

WEnd



Func CheckScreen()

    ; Random chance of success
    If Random(0, 1) > 0.9 Then
        $bConfirm = True
    EndIf



EndFunc



Func InformUser($iIndex, $iMode)

    ; Determine if success or failure
    $sMsg = ( ($iMode = 1) ? (" Succeeded") : (" Failed") )
    ; Tell user
    ConsoleWrite("!Update " & $iIndex & $sMsg & @CRLF)
    
EndFunc

Obviously as I do not have access to the various functions you call I have had to produce my own, but I hope that the logic flow does what you require: keep looping until there have been as many success/fail events as there are updates. I can well imagine that you may need to introduce some form of check to make sure that you do not keep counting the same update on every pass - this would be trivial to achieve, but without more details I cannot suggest a suitable method.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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