Jump to content

Why is my script freezing?


Recommended Posts

So, I made my script to automate some tedious parts of my work. It works through two GUIs that take information from the user and enacts a process. I set it up so that the first GUI would close itself and open the next once the information had been entered and the button pressed. 

However, the second GUI takes 5-6 buttons presses to run; it's rather frustrating. Any help would be appreciated.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
#include <AutoItConstants.au3>

HotKeySet("{`}", "Terminate")
Func Terminate()
    Exit
 EndFunc   ;==>Terminate

Login ()

Func Login ()
$Login = GUICreate("Login", 300, 80)
GUICtrlCreateLabel("Name and Extension:", 10, 15, 85, 25)
$idNameExt = GUICtrlCreateInput("", 80, 10, 200, 25)
$NEXT = GUICtrlCreateButton("Next", 120, 45, 60, 25)

GUISetState(@SW_SHOW)

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
   Case $NEXT
            Global $NameExt = GUICtrlRead($idNameExt)
            GUIDelete($Login)
            Main ()
         Case $GUI_EVENT_CLOSE
            Exit
         EndSwitch
      WEnd
EndFunc

Func Main ()

$MAIN = GUICreate("Loans", 220, 560)
GUICtrlCreateLabel("ICN:", 10, 15, 65, 25)
$idICN = GUICtrlCreateInput("", 80, 10, 120, 25)
GUICtrlSetLimit(-1, 12)
GUICtrlCreateLabel("Transit:", 10, 55, 65, 25)
$idTransit = GUICtrlCreateInput("", 80, 50, 120, 25)
GUICtrlSetLimit(-1, 5)
GUICtrlCreateLabel("Queue:", 10, 95, 65, 25)
$idQueue = GUICtrlCreateCombo("Lending", 80, 90, 120, 25)
GUICtrlSetData($idQueue, "Real Estate|Corp", "Lending")
GUICtrlCreateLabel("Case #:", 10, 135, 65, 25)
$idCase = GUICtrlCreateInput("", 80, 130, 120, 25)
GUICtrlSetLimit(-1, 9)
GUICtrlCreateLabel("Serial:", 10, 175, 65, 25)
$idSerial = GUICtrlCreateInput("", 80, 170, 120, 25)
GUICtrlSetLimit(-1, 10)
GUICtrlCreateLabel("Value Date:", 10, 215, 65, 25)
$idPVD = GUICtrlCreateInput("", 80, 210, 120, 25)
GUICtrlSetLimit(-1, 8)
GUICtrlCreateLabel("Amount:", 10, 255, 65, 25)
$idAmount = GUICtrlCreateInput("", 80, 250, 120, 25)
GUICtrlCreateLabel("Currency:", 10, 295, 65, 25)
$idCurrency = GUICtrlCreateCombo("CAD", 80, 290, 120, 25)
GUICtrlSetData($idCurrency, "USD", "CAD")
GUICtrlCreateLabel("Ordering:", 10, 335, 65, 25)
$idOrdering = GUICtrlCreateInput("", 80, 330, 120, 25)
GUICtrlCreateLabel("Contra:", 10, 375, 65, 25)
$idContra = GUICtrlCreateInput("", 80, 370, 120, 25)
GUICtrlSetLimit(-1, 4)
GUICtrlCreateLabel("Beneficiary:", 10, 415, 65, 25)
$idName = GUICtrlCreateInput("", 80, 410, 120, 25)
GUICtrlCreateLabel("Identifier:", 10, 455, 65, 25)
$idIdentifier = GUICtrlCreateInput("", 80, 450, 120, 25)
GUICtrlSetLimit(-1, 26)
GUICtrlCreateLabel("Authorization:", 10, 495, 65, 25)
$idAuthorization = GUICtrlCreateInput("", 80, 490, 120, 25)
$RUN = GUICtrlCreateButton("RUN", 80, 525, 60, 25)

   GUISetState(@SW_SHOW)

    While 1
       $nMsg = GUIGetMsg()
       Switch GUIGetMsg()
       Case $GUI_EVENT_CLOSE
          Exit
       Case $RUN
                Global $ICN = GUICtrlRead ($idICN)
                Global $Transit = GUICtrlRead ($idTransit)
                Global $Queue = GUICtrlRead ($idQueue)
                  If $Queue = "Lending" Then
                     $Queue = "LCOMM"
                  ElseIf $Queue = "Real Estate" Then
                     $Queue = "LREAL"
                  Else
                     $Queue = "LCORP"
                  EndIf
                Global $Case = GUICtrlRead ($idCase)
                Global $Serial = GUICtrlRead ($idSerial)
                Global $PVD = GUICtrlRead ($idPVD)
                Global $Amount = GUICtrlRead ($idAmount)
                Global $Currency = GUICtrlRead ($idCurrency)
                Global $Ordering = GUICtrlRead ($idOrdering)
                Global $Contra = GUICtrlRead ($idContra)
                Global $Name = GUICtrlRead ($idName)
                Global $Identifier = GUICtrlRead ($idIdentifier)
                Global $Authorization = GUICtrlRead ($idAuthorization)

            If StringLen($ICN) < 12 Then
               MsgBox(0,'Error','Check ICN')
            ElseIf StringLen($Transit) < 5 Then
               MsgBox(0,'Error','Check Transit')
            ElseIf StringLen($Serial) < 10 Then
               MsgBox(0,'Error','Check Serial')
            Else
               WinActivate ( "Session A" )
               WinMove("Session A", "", 1, 1)
               WinSetState ( "Session A", "", @SW_SHOW )
               WinSetState ( "Session A", "", @SW_ENABLE )
               WinSetState ( "Session A", "", @SW_MAXIMIZE )
               WinSetState ( "Session A", "", @SW_MAXIMIZE )
               WinSetState ( "Session A", "", @SW_MAXIMIZE )
               Opt("SendKeyDelay", 10)
               If Not $Case Then
                  Send("1" & "{Enter}")
                  Send("BSC " & $Name & "{F6}")
                  Send($Identifier)
                  Send("{Enter}" & "{Enter}" & "{Enter}" & "{Enter}" &  "{Enter}")
                  MouseClickDrag($MOUSE_CLICK_LEFT, 336, 209, 1340, 582, 2)
                  MouseClick("left", 43,55, 5, 1)
                  $Case = StringTrimLeft(ClipGet(), StringInStr(ClipGet(), "Case ID") + 35)
                  $Case = StringTrimRight($Case, StringLen ( $Case ) - 9)
                  $Contra = StringRight ($Case, 4)
                  Send("{F11}")
                  Send("Client Name on the Wire: " & $Name & " / TRN: " & $Transit & "{TAB}")
                  Send("Amount of Funds/Currency: " & $Amount & " / " & $Currency & "{TAB}")
                  Send("Value Date: " & $PVD & " / " & "PVD: " &  _NowDate ( ) & "{TAB}")
                  Send("Wire Serial / ICN CA: " & $Serial & " / " &  $ICN & "{TAB}")
                  Send("Contra / Currency: " & $Contra & " / " &  $Currency & "{TAB}")
                  Send("{PGDN}")
                  Send("Account Number (if listed):" & "{TAB}")
                  Send("Additional Instructions:" & "{TAB}")
                  Send("Authorized by: " & $Authorization & "{Tab}")
                  Send("NAME & EXTENSION: " & $NameExt & "{Enter}")
                  Send("{F12}" & "{F7}")
                  If $Queue = "LCOMM" Then
                     Send("BSCTLSWHLD" & "{Enter}" & "{Enter}" & "{Enter}")
                  ElseIf $Queue = "LREAL" Then
                     Send("BSCTREWS" & "{Enter}" & "{Enter}" & "{Enter}")
                  Else
                     Send("BSCCORPCT" & "{Enter}" & "{Enter}" & "{Enter}")
                  EndIf
                  Send("{F3}" & "{F3}" & "{F3}" & "{F3}" & "{F12}" & "{F12}" & "{F12}")
               Else
                  Send("2" & "{Enter}")
                  Send("1" & "{Enter}" & "{Enter}" & "{Enter}")
                  Send("{DOWN}" & $Case & "{Enter}" & "{Enter}" & "{Enter}")
                  Send("{F11}")
                  Send("Client Name on the Wire: " & $Name & " / TRN: " & $Transit & "{TAB}")
                  Send("Amount of Funds / Currency: " & $Amount & " / " & $Currency & "{TAB}")
                  Send("Value Date: " & $PVD & " / " & "PVD: " & _NowDate ( ) & "{TAB}")
                  Send("Wire Serial / ICN CA: " & $Serial & " / " &  $ICN & "{TAB}")
                  Send("Contra / Currency: " & $Contra & " / " &  $Currency & "{TAB}")
                  Send("{PGDN}")
                  Send("Account Number (if listed):" & "{TAB}")
                  Send("Additional Instructions:" & "{TAB}")
                  Send("Authorized by: " & $Authorization & "{Tab}")
                  Send("NAME & EXTENSION: " & $NameExt & "{Enter}" & "{Enter}" & "{Enter}")
                  Send("{F12}" & "{F12}" & "{F12}" & "{F12}" & "{F12}")
               EndIf

               WinActivate ("Teller Menu")
               Opt("SendKeyDelay", 0)
               Send("!s")
               Send("!b")
               Send("!b")
               Send("!b")
               Send("!b")
               Send("!b")
               Send($Transit)
               If $Currency = "CAD" Then
                  Send("{F8}" & "{F8}" & "{F8}" & "{F8}" & "{F8}")
                  Sleep ( 100 )
                  Send("{F8}" & "{F8}" & "{F8}" & "{F8}" & "{F8}")
                  Send("p" & "{TAB}")
                  Send($Amount & "{TAB}" & $Serial & "{TAB}" & "{TAB}" & $Ordering & "{TAB}" & "{PGDN}" & "{TAB}" & "{PGDN}" & "{Enter}")
                  Send("{F9}" & "{F9}" & "{F9}" & "{F9}" & "{F9}")
                  Sleep ( 100 )
                  Send("{F9}" & "{F9}" & "{F9}" & "{F9}" & "{F9}")
                  Send("{DOWN}" & "{TAB}" & $Amount & "{TAB}" & "1304968" & "{TAB}" & $Queue & " " & $Name & "{TAB}" & $Contra & "{Enter}")
                  Send("!p")
                  Sleep ( 750 )
                  Send("!e")
                  Send("!e")
                  Send("!e")
                  Send("!e")
                  Send("!e")
               Else
                  Send("{F10}")
                  Sleep ( 1000 )
                  Send("{F8}" & "{F8}" & "{F8}" & "{F8}" & "{F8}")
                  Sleep ( 100 )
                  Send("{F8}" & "{F8}" & "{F8}" & "{F8}" & "{F8}")
                  Send("p" & "{TAB}")
                  Send($Amount & "{TAB}" & "{TAB}" & $Serial & "{TAB}" & "{TAB}" & $Ordering & "{TAB}" & "{PGDN}" & "{TAB}" & "{PGDN}" & "{Enter}")
                  Send("{F9}" & "{F9}" & "{F9}" & "{F9}" & "{F9}")
                  Sleep ( 100 )
                  Send("{F9}" & "{F9}" & "{F9}" & "{F9}" & "{F9}")
                  Send("{DOWN}" & "{TAB}" & $Amount & "{TAB}" & "1304968" & "{TAB}" & $Queue & " " & $Name & "{TAB}" & $Contra & "{Enter}")
                  Send("!e")
                  Send("!p")
                  Sleep ( 500 )
                  WinActivate ("Specify GL")
                  Send("!c")
                  Sleep ( 500 )
                  Send("!e")
                  Send("!e")
                  Send("!e")
                  Send("!e")
                  Send("!e")
               EndIf

               WinActivate ("Contra Log")
               WinActivate ("Contra Log")
               WinActivate ("Contra Log")
               Opt("SendKeyDelay", 15)
               Send(_NowDate ( ) & "{RIGHT}" & $Transit & "{RIGHT}" & "{RIGHT}" & "{RIGHT}" & $Currency & "{RIGHT}" & $Contra & "{RIGHT}" & $Amount & "{RIGHT}" & $Case & "{RIGHT}" & $Queue & " " & $Name)
               Send("{DOWN}" & "{LEFT}" & "{LEFT}" & "{LEFT}" & "{LEFT}" & "{LEFT}" & "{LEFT}" & "{LEFT}" & "{LEFT}")

               WinActivate ("Loans")
            EndIf
        EndSwitch
     WEnd
     EndFunc

 

Link to comment
Share on other sites

At the top of your script add AutoItSetOption ("TrayIconDebug", 1)  what that will do is tell you what line your script is stopped on when you hover your mouse over the AI icon in the tray while it's running. I'm not sure if that would help you, but if it would then you can try it.

Edited by noobieautolearn
Link to comment
Share on other sites

Here is a little "faux pas" to fix.

....
 While 1
       $nMsg = GUIGetMsg()
       ; Switch GUIGetMsg() ; <- Not this 
       Switch $nMsg         ; <- This  
           Case $GUI_EVENT_CLOSE
               Exit
           Case $RUN
               ....

However you fix this, only have one GUIGetMsg() function in each While-Wend loop.

Link to comment
Share on other sites

On 5/23/2018 at 6:57 PM, Malkey said:

However you fix this, only have one GUIGetMsg() function in each While-Wend loop.

Hi, thanks for this! I edited my script and the freezing/lagging error has stopped. Pretty sure this was what was causing it in the first place. 

Link to comment
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
 Share

  • Recently Browsing   0 members

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