Sign in to follow this  
Followers 0
crushyna

Error check implementation (problem with loop exit)

1 post in this topic

Hi everyone!
I'm developing small testing tool for new software in my company.
Tool itself is working correctly (it follows scripted test commands one by one), but I'm trying to develop an error checking function.

Mechanics are simple: every time software (external) shows specific error (via window class), program asks for next step. Continue, or abort test (and return to main GUI)?
The error check function is switched on/off via Checkbox in GUI.

Here are some code fragments:

Checkbox:

Global $idCheckbox1 = GUICtrlCreateCheckbox("Enable TP.net error handling", 352, 40, 249, 17)
    GUICtrlSetFont(-1, 12, 400, 0, "Calibri")
    GUICtrlSetColor(-1, 0x000000)

 

Checkbox switch:

GUISetState(@SW_SHOW)
Local $Choosen

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $idCheckbox1
            If _IsChecked($idCheckbox1) Then
                $cSwitch1 = 1
            Else
                $cSwitch1 = 0
            EndIf

        Case $idAddTest
(and so on...)

 

Function call:

(alot of ElseIf commands...)

                    ElseIf $aItem = $idOperatorIn Then
                    WywolanieOkna()
                    WinActivate($hFSO)
                    ControlClick($hFSO, "", "[NAME:lblCashierNumber]")
                    Sleep($Sleep_05)
                    Send("0000019{Enter}19{Enter 2}")
                    Sleep($Sleep_75)

                EndIf

                #EndRegion ### START ELSEIF ARMY ###

        Next
        If $cSwitch1 = 1 Then
            MsgBox( 0, "Error check!", "Error check ON!")  /// just for testing purposes
            CheckError()
        Else
            Return
        EndIf
    EndSwitch
WEnd


Classic _IsChecked function:

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

 

And Checkerror() function itself:

Func CheckError()
    Local $Answer
    If ControlCommand($hMsgPanel, "", "[NAME:panelMsgBox]", "IsEnabled", "") Then
;~      Sleep($Sleep_05)
        $Answer = MsgBox(52, "Error!", "An error occured! Continue testing?")
;~      Sleep($Sleep_05)
        Switch $Answer
            Case 6
                MsgBox(0, "Error!", "Test will now continue.", 3)
                Send("{Enter}")
                WinActivate($hWnd)
                Return
            Case 7
                MsgBox(64, "Error!", "Test cancelled.", 5)
                $ElseIfArmyOff = 1
                ControlClick($hMsgPanel, "", "[NAME:cmdOK]")
                WinActivate($AppName)
                #cs
                    MsgBox( 0, "test1", $idTSList)
                    Local $idTSListCopy
                    For $i = 0 to _GUICtrlListView_GetItemCount($idTSList) - 1\
                #ce
                $idTSListCopy = _GUICtrlListView_GetItemTextString($idTestCaseList, $LoopCount)
                ExitLoop
        EndSwitch
    EndIf
    Return 1
EndFunc   ;==>CheckError


Problem is: i can't make this function (CheckError() ) return to main gui state, that means: break the If/ElseIf loop.
The switch is working correctly (MsgBox on error shows only when it's activated).
Checkerror() function works correctly - recognizes the error, stops script until decision is made. But it doesn't terminate If/ElseIf loop.

Any help appreciated!

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

  • Similar Content

    • Em4gdn1m
      By Em4gdn1m
      Hey everyone, I'm curious if there is a way to incorporate a checkbox with a combo GUICtrl?
      so for instance I have a GUI that has a bunch of checkboxes that allow me to open certain programs as needed.  (this is just some parsing of my code, sorry, noob here and not sure what the preferred method of displaying code is, please enlighten me)

          $L0742 = GUICtrlCreateCheckbox("L07 4.2", 110, 320, 100)
          $L07502 = GUICtrlCreateCheckbox("L07 5.0.2", 110, 350, 100)
          $GenComm = GUICtrlCreateCheckbox("GenComm", 110, 380, 100)
          $Templates = GUICtrlCreateCheckbox("Templates", 110, 410, 100)
          $MCT = GUICtrlCreateCheckbox("MCT", 110, 440, 100)
          $Desktop_Shortcuts = GUICtrlCreateCheckbox("Desktop Shortcuts by Tester", 110, 470, 200)
       
      ...
      Case $msg = $RunBtn
                  RunPrograms()
       
      ...
      Func RunPrograms()

          if GUICtrlRead($L0742) = $GUI_CHECKED then Run("C:\Program Files\Varian\Paxscan\L07 Rel4.2\viva\viva.exe", "")
          if GUICtrlRead($L07502) = $GUI_CHECKED then Run("C:\Program Files\Varian\Paxscan\L07 Rel5\viva\viva.exe", "")
          if GUICtrlRead($GenComm) = $GUI_CHECKED then Run("\\Fpanelfs1\FPShared\Desktop_Shortcuts_by_Tester\Matt\CPI Generator\CPI Generator Windows 7 64 Bit\GenComm\GenComm.NET.exe", "")
          if GUICtrlRead($Templates) = $GUI_CHECKED then ShellExecute("\\Fpanelfs1\FPProjects\Documentation Controlled\Test_Templates")
          if GUICtrlRead($MCT) = $GUI_CHECKED then Run("\\Fpanelfs1\FPProjects\Documentation Controlled\Manufacturing Software\MCT\MCT.exe","")
          if GUICtrlRead($Desktop_Shortcuts) = $GUI_CHECKED then ShellExecute("\\Fpanelfs1\fpshared\Desktop_Shortcuts_by_Tester")
      EndFunc
       
      so i click some checkboxes, and hit a run button and the programs which are checked run, great.
      BUT i want to add a bunch of options under one checkbox. A combo that will list a bunch of versions of a program that can be opened. something like this... but I want that program to be part of a checkbox
      $ViVAComboBox = GUICtrlCreateCombo("L01 Rel 13", 110, 320, 100)
      GUICtrlSetData($ViVAComboBox, "L04|L05|L07 Rel 4.2|L07 Rel 5.0.2|L09", "L07 Rel 4.2")
       
      is this possible? is there another GUICtrl that does this better that i am not aware of?
       
       
    • fosil
      By fosil
      Hi all,

      I'm working on a relatively complex automation program and I need it to call a specific function when it is closed by a user. Ive resorted to "OnAutoItExitRegister" as i believe that's the only option available.

      This command works perfectly fine in a small scale test application I wrote, but once implemented in the final program that's much larger and divided over many files in many directories it no longer works. I don't get any error messages.

      My question is has anyone encountered an issue where implementation of this command in a large scale program gave them trouble? Does it matter where "OnAutoItExitRegister" is called and where the function is located? Currently they are both places in the main file that runs the whole program but it still doesn't work.

      Any help is appreciated
    • Masum
      By Masum
      Hi all,
      Ctrl+Break stops script only if AutoIt window is active. It doesn't work while automation is going on elsewhere.
      Is there a way to stop the script regardless of where the automation is happening?
      Thanks
    • ruslanas402
      By ruslanas402
      Hello everyone, don't even know how to ask.  My code is:
      #include <String.au3> #include <IE.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 700, 500, 192, 124) $Button1 = GUICtrlCreateButton("View", 576, 24, 89, 41) Global $oIE = _IECreate("https://www.youtube.com/playlist?list=PL4Jcq5zn02jKpjX0nqI1_fS7mEEb5tw6z", 1, 1, 0) Sleep(1000) Global $sHTML = _IEDocReadHTML($oIE) $FirstChunks = _StringBetween($sHTML, 'pl-video-title-link yt-uix-tile-link yt-uix-sessionlink', '<div class="pl-video-owner') $x = 16 For $a In $FirstChunks $actualdata = _StringBetween($a, '">', '</a>') ;$actualdata2 = _StringBetween($a, 'href="', '&amp;') $Checkbox1 = GUICtrlCreateCheckbox($actualdata[0], 24, $x, 500, 17) $x = $x + 20 Next GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Somehow I need to open webpages where checkbox is checked by presing button view, I think I need somehow asign $actualdata with $actualdata2. Any ideas would be very appreciated
    • Comboku
      By Comboku
      Hi Guys,
      I have written a little loop program that counts to whatever you choose in "Rounds". 

      (this is just a short version of my program, but it should cover what I try to achieve)

      I now want to be able to stop the counting by pressing the start/stop button. Unfortunately, autoit only registers my click on my button AFTER the func has ended.

      Do you guys have an idea how to stop the function? Maybe check if button was pressed in the loop? 


      Thanks,

      Comboku

       
       
       
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <IE.au3> #include <Array.au3> #include <File.au3> $Form1 = GUICreate("Looper", 355, 229, 435, 293) $StartStop = GUICtrlCreateButton("Start", 136, 184, 75, 25) $Rounds = GUICtrlCreateInput("1", 210, 40, 80, 21) $lRounds = GUICtrlCreateLabel("Rounds", 298, 42, 52, 18) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $StartStop If GUICtrlRead($StartStop) = "Start" Then GUICtrlSetData($StartStop, "Stop") GUICtrlSetState($Rounds, $GUI_DISABLE) Call("Loop") ElseIf GUICtrlRead($StartStop) = "Stop" Then ExitLoop MsgBox(0, "Info", "Stopped") Else MsgBox(0, "Info", "Error") EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func Loop() $LoopTimes = GUICtrlRead($Rounds) For $i = 1 To $LoopTimes MsgBox(0, "Info", "LET US COUNT: " & $i) Sleep("2000") Next GUICtrlSetData($StartStop, "Start") GUICtrlSetState($StartStop, $GUI_ENABLE) GUICtrlSetState($Rounds, $GUI_ENABLE) EndFunc