Sign in to follow this  
Followers 0
SorryButImaNewbie

Revising my code + can ControlSetText exit the script?

3 posts in this topic

#1 ·  Posted (edited)

Hello everyone!

I try to improve a few of my scripts with additional features that would make it a bit more user friendly. After reading a topic here, I decided that I would like to make it, that my script remember a path to a program it needs to automate, so idealy the user only have to "show" it once and then it finds it automaticly. I want to use basicly the same scripts for a few different programs. I think that what I have now will be quite easy to adapt to my other scripts.

I would like to hear your opinion about what I made, I tried to make it so that even if they choose the wrong folder, or somehow the .ini file with the path is corrupted or what ever, the script till find a way to open it.

code:

Func UD_uszi_belepes() 

   If WinExists("UDUsziMainForm") Then ;check if the program is actually running or not
        MsgBox(0, "Üzenet", "Az UD_üszi már fut!")
        $UD_uszi_belepesRun = False
        Return
   EndIf

   If FileExists(@ScriptDir &"\PathToUszi.ini") = 1 Then ;If ww have a .ini file in our scriptdir then use that
      $iniRead = IniRead(@ScriptDir &"\PathToUszi.ini", "Folder", "Location", "")
      ;MsgBox(0, "", "Beolvassa a .init")
      Run($iniRead & "\UD_uszi.exe")
      ;MsgBox(0, "", "Futatja/Run function")
      Sleep(1000)
      Local $UD_usziBelepes = WinWaitActive("UD ÜSZI", "", 5)
      If $UD_usziBelepes = 0 Then
         Local $sFileSelectFolder = FileSelectFolder("Adja meg az UD_uszi.exe helyét!", "")
         Run($sFileSelectFolder & "\UD_uszi.exe")
         WinWaitActive("UD ÜSZI", "", 5)
         ControlSetText("TLoginForm", "UD ÜSZI", "TEdit2", $AccountName)
         Send("{TAB}"& $AccountPass)
         Sleep(50)
         Send("{ENTER}")
         $sFileSelectFolder = IniWrite (@ScriptDir &"\PathToUszi.ini", "Folder", "Location", $sFileSelectFolder)
      Else
         ControlSetText("TLoginForm", "UD ÜSZI", "TEdit2", $AccountName)
         Send("{TAB}"& $AccountPass)
         Sleep(50)
         Send("{ENTER}")
         $UD_uszi_belepesRun = False
         Return
      EndIf
   Else ;File dosn't exists

   Local $sFileSelectFolder = FileSelectFolder("Adja meg az UD_uszi.exe helyét!", "")
   Local $UD_usziBelepes = WinWaitActive("UD ÜSZI", "", 15)
      If $UD_usziBelepes = 0 Then
        MsgBox(0, "Üzenet", "A kérés feldolgozási ideje magas!" & @CRLF & "Kérem próbálja újra, vagy nyissa meg manuálisan.")
        $UD_uszi_belepesRun = False
        Return ;user has given wrong path, exite from function, he can retry it from the GUI again basicly
      Else
        Local $WhereisFolder = IniWrite (@ScriptDir &"\PathToUszi.ini", "Folder", "Location", $sFileSelectFolder)
        ControlSetText("TLoginForm", "UD ÜSZI", "TEdit2", $AccountName)
        Send("{TAB}"& $AccountPass)
        Sleep(50)
        Send("{ENTER}") ;if user choose right, enter the program, save the path
      EndIf
   EndIf

    $UD_uszi_belepesRun = False

EndFunc   ;==>UD_uszi_belepes

During my testing I have meet an interesting phenomenon. When I rewrote the PathToUszi file, so that the path would not lead the exe, and tried to run this:

If FileExists(@ScriptDir &"\PathToUszi.ini") = 1 Then
      $iniRead = IniRead(@ScriptDir &"\PathToUszi.ini", "Folder", "Location", "")

      MsgBox(0, "", "Beolvassa a .init")

      Run($iniRead & "\UD_uszi.exe")

      MsgBox(0, "", "Futatja/Run function")

      Sleep(2000)

      MsgBox(0, "", "Alvás")

      ControlSetText("TLoginForm", "UD ÜSZI", "TEdit2", $AccountName)

      MsgBox(0, "", "TEdit Acc név")

      Send("{TAB}"& $AccountPass)
      Sleep(50)
      Send("{ENTER}")
      $UD_uszi_belepesRun = False
      Return
   EndIf

My script terminated when it reached "ControlSetText("TLoginForm", "UD ÜSZI", "TEdit2", $AccountName)"

Why is that? (I debug with this method, because I would have to reinstall the fullscite I think, which was somehow lost, and I would need a lot of administration for that... I only work here for 2 weeks so I don't really want to bother with it, I will be able to script what ever I need/want after this at home :D )

Thank you for your help and insight!

Edit: edited out an extra line of Return

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites



There is no reason in that script that it should exit at that point.

Thought so, I won't be able to solve that question without properdebugging.

Thx anyway

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