JailDoctor Posted May 5, 2008 Share Posted May 5, 2008 I'm reading each line of a .txt file and entering the numbers into an external application. When the user selects a wrong choice, a window called "Flowcast" appears. When this happens I wanted something like "GOTO" (I know this is obsolete, and there are better ways to do it.) So, how can I get the loop to go back to read the next line in the .txt file if the user chooses to skip this value, or enter a different value as the InputBox selection.CODE#include <ExcelCOM_UDF.au3>#include <adfunctions.au3> #include <File.au3> While 1 Dim $line, $file $line = FileReadLine($file) If @error = -1 Then ExitLoop If $line = "" Then ExitLoop ;Stop on empty line. WinActivate("aixidx Winsock - IDXterm") WinWaitActive("aixidx Winsock - IDXterm") Send(".") Send($line) Send("{ENTER}") Sleep(500) Send("TL") Sleep(500) WinWaitActive("aixidx Winsock - IDXterm") ;wait for window Dim $Value $Value = InputBox("Visit Number", "Select the Visit Number you wish to change.", "1"); Numbers only If $Value = 0 Then Exit Send($Value) Send("{ENTER}") Sleep(300) ;Edit the visit. Send("E") ;enter today's date. Send("T{ENTER}") ;check for wrong visit If WinExists("Flowcast") Then ;A window called Flowcast appears on error. MsgBox(6, "Wrong Choice", "You selected a discharged visit, please try again.") GUICreate("Custom Msgbox", 210, 80) $Label = GUICtrlCreateLabel("Please click a button!", 10, 10) $TryAgainID = GUICtrlCreateButton("Try Again", 10, 50, 50, 20) ; I want to go back to $Value = InputBox ("Visit Number", "Select the Visit Number you wish to change.", "1"); Numbers only $SkipID = GUICtrlCreateButton("Skip", 80, 50, 50, 20) ; I want to skip this array and start all over with the next array at $line = FileReadLine($file) $ExitID = GUICtrlCreateButton("Exit", 150, 50, 50, 20) ; Exit is easy. GUISetState() ; display the GUI Sleep(300) ;Enter the time (now). Send("N{ENTER}") Sleep(300) Send($Location) Sleep(300) Send("{ENTER}") Sleep(300) Send("{F10}") Sleep(300) Send("{F10}") Sleep(300) Send("{F10}") Sleep(300) Send("{UP}") Sleep(300) WEnd Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 5, 2008 Share Posted May 5, 2008 ContinueLoop()??? .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
JailDoctor Posted May 5, 2008 Author Share Posted May 5, 2008 ContinueLoop doesn't seem to work with While-WEnd. Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 5, 2008 Share Posted May 5, 2008 ContinueLoop doesn't seem to work with While-WEnd.Yes it does. How did you try to use it? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
JailDoctor Posted May 5, 2008 Author Share Posted May 5, 2008 (edited) This is how I'm using ContinuLoop. It should proceed to the next array (.txt file line) but instead it hangs and I have to exit manually. This bold areas are the key points where I want to go to. ContinueLoop is in red.CODE$file = FileOpen(@TempDir & "\My Test List.txt", 0) ;Define from which file to read MRNs.If $file = -1 Then ; Check if the file can open. MsgBox(0, "Error", "Missing MRN List.") ExitEndIfWhile 1 Dim $line, $file $line =FileReadLine($file) If @error = -1 Then ExitLoop If $line = "" Then ExitLoop ;Stop on empty line. If @error = -1 Then ExitLoop WinActivate("aixidx Winsock - IDXterm") WinWaitActive("aixidx Winsock - IDXterm") Send(".") Send($line) Send("{ENTER}") Sleep(500) Send("TL") Sleep(500) WinWaitActive("aixidx Winsock - IDXterm") ;wait for the window Dim $Value $Value = InputBox("Visit Number", "Select the Visit Number you wish to change.", "1") If $Value = 0 Then Exit Send($Value) Send("{ENTER}") Sleep(300) ;Edit the visit. Send("E") ;enter today's date. Send("T{ENTER}") ;check for wrong visit If WinExists("Flowcast") Then GUICreate("Custom Msgbox", 210, 80) $Label = GUICtrlCreateLabel("Please click a button!", 10, 10) $TryAgainID = GUICtrlCreateButton("Try Again", 10, 50, 50, 20) $SkipID = GUICtrlCreateButton("Skip", 80, 50, 50, 20) $ExitID = GUICtrlCreateButton("Exit", 150, 50, 50, 20) GUISetState() ; display the GUI Do $msg = GUIGetMsg() Select Case $msg= $TryAgainID ; this is where I want to go back to $Value WinWait("Flowcast", "") If Not WinActive("Flowcast", "") Then WinActivate("Flowcast", "") WinWaitActive("Flowcast", "") Send("{ENTER}") Send("{ENTER}") WinWaitActive("Flowcast", "") ;We know its wrong. ; Start all over. WinWait("aixidx Winsock - IDXterm", "") If Not WinActive("aixidx Winsock - IDXterm", "") Then WinActivate("aixidx Winsock - IDXterm", "") WinWaitActive("aixidx Winsock - IDXterm", "") Send("{F7}q{F7}q{F7}q1{ENTER}") Send(".") Send($line) Send("{ENTER}") Sleep(1000) Send("TL") Case $msg= $SkipID ContinueLoop ; this is where the Array should skip and start a new turn of the loop. Case $msg= $ExitID MyExit() Case $msg= $GUI_EVENT_CLOSE MsgBox(0,"You clicked on", "Exit") EndSelect Until $msg = $GUI_EVENT_CLOSE or $msg = $ExitID $Value = InputBox("Visit Number", "Select the Visit Number you wish to change.", "1") Opt("WinTitleMatchMode", 2) ; Match substring WinSetTrans("Visit Number", "", 70) ; Make Notepad window semi-transparent. If $Value = 0 Then Exit Send($Value) Send("{ENTER}") Sleep(300) Send("E") Send("T{ENTER}") EndIf Sleep(300) ;Enter the time (now). Send("N{ENTER}") Sleep(300) Send($Location) Sleep(300) Send("{ENTER}") Sleep(300) Send("{F10}") Sleep(300) Send("{F10}") Sleep(300) Send("{F10}") Sleep(300) Send("{UP}") Sleep(300) WEnd Edited May 5, 2008 by JailDoctor Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 5, 2008 Share Posted May 5, 2008 While 1 ; ... Do $msg = GUIGetMsg() Select Case $msg= $TryAgainID ; ... Case $msg= $SkipID ContinueLoop Case $msg= $ExitID MyExit() Case $msg= $GUI_EVENT_CLOSE MsgBox(0,"You clicked on", "Exit") EndSelect Until $msg = $GUI_EVENT_CLOSE or $msg = $ExitID ; ... WEnd Your instance of ContinueLoop is inside a Do/Until loop and that is the loop being continued. If you want to exit the Do/Until and continue the While/WEnd loop, use the "level" option: Case $msg= $SkipID ContinueLoop 2 Also, run Tidy on your code (Ctrl-T) and post it inside code tags so your code isn't so annoying to read. That will get you quicker/more helpful answers. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
JailDoctor Posted May 5, 2008 Author Share Posted May 5, 2008 I just fixed the code bar, sorry. Link to comment Share on other sites More sharing options...
MikeP Posted May 5, 2008 Share Posted May 5, 2008 (edited) you can use [auto.it] [/auto.it] too to use autoit syntax coloring (without the .) Edited May 5, 2008 by MikeP Link to comment Share on other sites More sharing options...
JailDoctor Posted May 5, 2008 Author Share Posted May 5, 2008 (edited) Your instance of ContinueLoop is inside a Do/Until loop and that is the loop being continued. If you want to exit the Do/Until and continue the While/WEnd loop, use the "level" option: Case $msg= $SkipID ContinueLoop 2 Also, run Tidy on your code (Ctrl-T) and post it inside code tags so your code isn't so annoying to read. That will get you quicker/more helpful answers. You are right! I was testing ContinueLoop, 1 Thinking this would tell the loop to go to the first loop. Any suggestions to GOTO the $Value Input box and enter the same array so the user chooses the right selection? Edited May 5, 2008 by JailDoctor Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 5, 2008 Share Posted May 5, 2008 Any suggestions to GOTO the $Value Input box and enter the same array so the user chooses the right selection?Questions on using GOTO in AutoIt scripts are handled by... Valik. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
JailDoctor Posted May 6, 2008 Author Share Posted May 6, 2008 Questions on using GOTO in AutoIt scripts are handled by... Valik. Well, its not really GOTO , I just call it that because of all the talk about how not necessary it is for AutoIt. I am learning AutoIt by reading forums, and the help file. For a newie like myself this is a wonderful scripting product.The question is how to repeat the last loop.So, when the script sees the window that pops up on an error, the user clicks on the "Try Again" button and the last variable is looped again.Is there such a command as repeat? Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 6, 2008 Share Posted May 6, 2008 The question is how to repeat the last loop.So, when the script sees the window that pops up on an error, the user clicks on the "Try Again" button and the last variable is looped again.Is there such a command as repeat?1. You can put some code in a function, and call that function as often as required.2. You can put some code in a function, and call it regularly with AdLibEnable() to see if something needs to be done (i.e. handle a pop up). 3. You can have a loop that continuously tests if something needs to be done and runs the code.If you want to handle this pop up window coming up unexpectedly and perhaps repeatedly, go with option 2. Every 250ms or so, it will test if the error pop up exists, and handle it if it does, then return to what it was doing before it was interrupted. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
JailDoctor Posted May 6, 2008 Author Share Posted May 6, 2008 If you want to handle this pop up window coming up unexpectedly and perhaps repeatedly, go with option 2. Every 250ms or so, it will test if the error pop up exists, and handle it if it does, then return to what it was doing before it was interrupted. I catch the erro window called Flowcast fine with:CODEIf WinExists("Flowcast") Then GUICreate("Wrong choice", 210, 80) $Label = GUICtrlCreateLabel("You selected a closed visit.!", 10, 10) $TryAgainID = GUICtrlCreateButton("Try Again", 10, 50, 50, 20) $SkipID = GUICtrlCreateButton("Skip", 80, 50, 50, 20) $ExitID = GUICtrlCreateButton("Exit", 150, 50, 50, 20) GUISetState() ; display the GUI Do $msg = GUIGetMsg();etcWhat I don't know how to do is: when the user clicks the "Try Again" button, repeat the loop with the same value so the user gets another chance to select the correct visit (or whatever the looped variable represents). Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 6, 2008 Share Posted May 6, 2008 I catch the erro window called Flowcast fine with: CODEIf WinExists("Flowcast") Then GUICreate("Wrong choice", 210, 80) $Label = GUICtrlCreateLabel("You selected a closed visit.!", 10, 10) $TryAgainID = GUICtrlCreateButton("Try Again", 10, 50, 50, 20) $SkipID = GUICtrlCreateButton("Skip", 80, 50, 50, 20) $ExitID = GUICtrlCreateButton("Exit", 150, 50, 50, 20) GUISetState() ; display the GUI Do $msg = GUIGetMsg() ;etcWhat I don't know how to do is: when the user clicks the "Try Again" button, repeat the loop with the same value so the user gets another chance to select the correct visit (or whatever the looped variable represents). If a specific action triggers this error popup, then you only need to conditionally test for it at that time. If detected, you want to restart the code, it seems. One way to do that would be to put it in a While/WEnd loop that is only intended to run once, but can be restarted by ContinueLoop, if an error occurs: While 1 ; Initialize conditions $Var1 = "1" $Var2 = "2" ; Perform actions _ActionOne() _ActionTwo() ; Check for error popup If WinWait("Error Popup", "You screwed up", 3) Then ContinueLoop; watch 3sec for error ; No error, next step _ActionThree() ; Done ExitLoop WEnd Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
JailDoctor Posted May 6, 2008 Author Share Posted May 6, 2008 I thought that ContinueLoop would use the next variable to run the loop. ContinueLoop will test Sam and not Monica, who generated the error I want to correct. CODEFile.txt contains: Albert Michael Monica Sam Walter While 1 $line = FileReadLine(File.txt) WinActivate (External Application) Send ($line) ;Application asks a question $Value = InputBox("Gender", "Select the persons gender.") If $Value = 0 Then Exit Send($Value) ;here I test for error. So if Monica was assigned a male gender, an error occurs. ;I want to have Monica offered as an option again to select the correct gender MsgBox(6, "Good call", $line & is & $Value WEnd Link to comment Share on other sites More sharing options...
JailDoctor Posted May 6, 2008 Author Share Posted May 6, 2008 2. You can put some code in a function, and call it regularly with AdLibEnable() to see if something needs to be done (i.e. handle a pop up).I did this part, so AdlibEnable("myadlib") checks for the pop up window with the error. Problem: A function resides out of the loop and can't go back to the loop after it is done.ERROR: 'ContinueLoop' not allowed outside loop.How do I continue the loop after a Function is called by AdlibEnable("myadlib")? Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 7, 2008 Share Posted May 7, 2008 I did this part, so AdlibEnable("myadlib") checks for the pop up window with the error. Problem: A function resides out of the loop and can't go back to the loop after it is done. ERROR: 'ContinueLoop' not allowed outside loop. How do I continue the loop after a Function is called by AdlibEnable("myadlib")? If you do it that way, then the function myadlib() will change some flag variable, like: Func myadlib() If WinExists("Error Popup") Then $fErrorPopup = True ControlSend("Error Popup", "", "", "!r"); Retry EndIf EndFunc Inside your loop, you would periodically test the $fErrorPopup flag and act accordingly. Make sure the flag gets cleared when the loop starts/restarts. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
JailDoctor Posted May 7, 2008 Author Share Posted May 7, 2008 (edited) If you do it that way, then the function myadlib() will change some flag variable, like: Func myadlib() If WinExists("Error Popup") Then $fErrorPopup = True ControlSend("Error Popup", "", "", "!r"); Retry EndIf EndFunc Inside your loop, you would periodically test the $fErrorPopup flag and act accordingly. Make sure the flag gets cleared when the loop starts/restarts. I don't understand the ControlSend("Error Popup", "", "", "!r"); Retry I created a function that changes the value of $fErrorPopup to True whenever the error window pops up. For some reason I can't get it to see the value. CODE$file = FileOpen(@TempDir & "\My Test List.txt", 0) ;Define from which file to read MRNs. If $file = -1 Then ; Check if the file can open. MsgBox(0, "Error", "Missing MRN List.") Exit EndIf While 1 Dim $Flowcast $Flowcast = False AdlibEnable("MYFlowcast") ;Check if the flag is true or false. Dim $line, $file $line = FileReadLine($file) ; Read the MRN number. If @error = -1 Then ExitLoop If $line = "" Then ExitLoop ;Stop on empty line. WinActivate("aixidx Winsock - IDXterm") ;Activate the external program. WinWaitActive("aixidx Winsock - IDXterm") Send(".") Send($line) ;send a period followed by the MRN number. Send("{ENTER}") Sleep(500) Send("TL") ;command to select a visit from a list. Sleep(500) WinWaitActive("aixidx Winsock - IDXterm") ;wait for the window Dim $Value $Value = InputBox("Visit Number", "Select the Visit Number you wish to change.", "1") ;Choose a Visit number from the visits shown (default is 1) If $Value = 0 Then Exit Send($Value) Send("{ENTER}") Sleep(300) ;Edit the visit. Send("E") ;To edit ;enter today's date. Send("T{ENTER}") ;for today ;check for wrong visit If $Flowcast = True Then ;Here is where I'm stuck. This should all be bypassed if $Flowcast is false, and run if True WinWait("Flowcast", "") ;this is the error window. If Not WinActive("Flowcast", "") Then WinActivate("Flowcast", "") WinWaitActive("Flowcast", "") ControlClick("Flowcast", "OK","") ;to get rid of the window WinWaitActive("Flowcast", "") Sleep (300) Send("{ENTER}");enter to get rid of a second Flowcast window that appears after Enter. ; Start all over. WinWait("aixidx Winsock - IDXterm", "") If Not WinActive("aixidx Winsock - IDXterm", "") Then WinActivate("aixidx Winsock - IDXterm", "") WinWaitActive("aixidx Winsock - IDXterm", "") Send("{F7}q{F7}q{F7}q1{ENTER}") ;all these keys are to go back to the initial screen and enter the same MRN number as before the Flowcast error window. MsgBox (0,"Cancelled Visit", "You selected a cancelled visit, Please try again.", 8000) 'Let the user know what to do. Send (".") Send ($line) $Value = InputBox("Visit Number", "Select the Visit Number you wish to change.", "1") If $Value = 0 Then Exit Send($Value) Send("{ENTER}") Sleep(300) ;Edit the visit. Send("E") ;enter today's date. Send("T{ENTER}") EndIf ;continue here if the flag $Flowcast is False. Sleep(300) ;Enter the time (now). Send("N{ENTER}") Sleep(300) Send($Location) Sleep(300) Send("{ENTER}") Sleep(300) Send("{F10}") Sleep(300) Send("{F10}") Sleep(300) Send("{F10}") Sleep(300) Send("{UP}") Sleep(300) WEnd Func MyFlowcast() If WinExists("Flowcast") Then $Flowcast = True ; If the window is present the flag is changed to True. ;ControlSend("Error Popup", "", "", "!r"); Retry -I don't understand this line. EndIf EndFunc Edited May 7, 2008 by JailDoctor Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 7, 2008 Share Posted May 7, 2008 I don't understand the ControlSend("Error Popup", "", "", "!r"); RetryIt was just an example of code handling the popup. This just sends Alt-r to the window "Error Popup". It was not meant to exactly match your circumstances, just be an example. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
JailDoctor Posted May 7, 2008 Author Share Posted May 7, 2008 It was just an example of code handling the popup. This just sends Alt-r to the window "Error Popup". It was not meant to exactly match your circumstances, just be an example. I get it.Ok, so Ihave the function already. When the Flowcast window appears, the function changes the value of the flag $Flowcast to True. So now that $Flowcast is true, it should follow the lines between If and EndIf, right?Somehow, it gets to where it clicks the Flowcast window's OK button ControlClick("Flowcast", "OK",""), and then jumps all the F7Q needed to go back to the original screen. Enters the letter N, and then the $Location variable. As in the lines after EndIf.I am obtunded.Please help! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now