mireazma Posted March 24, 2010 Share Posted March 24, 2010 I know it says in the manual that Goto is gone forever and no questions are allowed. That's why I didn't mention it in future versions requests (although it's not on the AutoItNotOnToDoList). I very much need goto and I'm trying to find a surogate for it: I have a bunch of If..Then..Endif lines and the script is executed liniarly. If something happens ('if' condition/switch) I want to re-initiate the bunch but each time from a different point in the bunch, with respect to the case of switch. Now how do I deal with this? Another time I encountered a situation where I wanted to move the flow of execution inside a loop. Goto was very a. transparent (you could follow the logical flow at a glance b. intuitive (if you wanted to jump to a certain line you could just... use the axiomatically simple Goto to do it) c. versatile (as in free, to jump wherever you wanted, up, down, in, out) d. ergonomic (you used a total amount of... 3 words: ":label" and "Goto, label". Related to this is that you could edit the script at a later time and if you wanted the jump removed, you could just delete the ":label" and Goto, label". How much does it cost you to change your mind with alternatives? e. fitted with AutoIt as this is a high level language structured on lines. I mean you can't easily continue a line on the next with "enter", like say, C++. Goto, rest in peace... Now I know there are alternatives and that's why I ask you what's the best one. 1. I use functions but I need to declare them at the beginning/end of script, then call them. And I have to make a function for every line in the bunch and nest the functions. 2. Another way is to make a big loop to contain the bunch plus the following code and put the Switch at the beginning of the loop, with Case set right before each "jump" line and a ContinueLoop to make the jump. Link to comment Share on other sites More sharing options...
FinalVersion Posted March 24, 2010 Share Posted March 24, 2010 Do ... Until [center][+] Steam GUI [+][+] Clipboard Tool [+][+] System :: Uptime [+][+] StarCraft II Mouse Trap [+][/center] Link to comment Share on other sites More sharing options...
Juvigy Posted March 24, 2010 Share Posted March 24, 2010 You are very wrong : Goto was very a. transparent (you could follow the logical flow at a glance b. intuitive (if you wanted to jump to a certain line you could just... use the axiomatically simple Goto to do it) c. versatile (as in free, to jump wherever you wanted, up, down, in, out) d. ergonomic (you used a total amount of... 3 words: ":label" and "Goto, label". Related to this is that you could edit the script at a later time and if you wanted the jump removed, you could just delete the ":label" and Goto, label". How much does it cost you to change your mind with alternatives? e. fitted with AutoIt as this is a high level language structured on lines. I mean you can't easily continue a line on the next with "enter", like say, C++. This is not true. GOTO is considered a "not good practice"/"do your best to avoid using it" in any language that supports it. Link to comment Share on other sites More sharing options...
Fulano Posted March 24, 2010 Share Posted March 24, 2010 Perhaps with some sample code we could give you better advice ... #fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja! Link to comment Share on other sites More sharing options...
jrumbaug Posted March 24, 2010 Share Posted March 24, 2010 Maybe I do not know your style of programing, but I HIGHLY recomend functions. They make the code much more readable and they are re-useable. Link to comment Share on other sites More sharing options...
madasraka Posted March 24, 2010 Share Posted March 24, 2010 (edited) If $something = "something" Then functionname();thats your GOTO ElseIf $something = "somethingElse" Then anotherfcuntion() ;GOTO else where or no function at all Was that what you were looking for ? I share your pain i wish autoit had GOTO function or GOTO line# or something Jumping over parts of code would be greate without having to work around it with functions and ton of If's If GOTO was in autoit i would have less If's and Functions made with ton of declared variables Edited March 24, 2010 by madasraka Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 24, 2010 Share Posted March 24, 2010 Any code that uses a goto can be written without (in languages that have other control structures).If your code is really so bad that it needs a goto, you probably need to rewrite it anyway. Link to comment Share on other sites More sharing options...
madasraka Posted March 24, 2010 Share Posted March 24, 2010 I dont think its about (code needs goto) i thinks its more about having simpler alternative. Just like CMD" Goto :Name :Name code continues here would be simpler then working with functions. Its all about simplicity and not functionality Link to comment Share on other sites More sharing options...
omikron48 Posted March 24, 2010 Share Posted March 24, 2010 What I was told about GOTO is that it should be avoided if other logic structures are available, to be on the safe side. While being clever with its use can save you using extra lines of code, the thing with GOTO is that it can easily be abused leading to convoluted code logic, especially on large programs. This can lead to more problems if the code in question is inherited by someone else and no proper documentation is available for it. As was mentioned earlier, it's good practice not to use it, as it is also good practice to put repeatedly used code into a separate function or making functions modular and as self-contained as possible/necessary because it helps with code maintenance. Link to comment Share on other sites More sharing options...
madasraka Posted March 25, 2010 Share Posted March 25, 2010 I agree 100% that it might cause issues with large codes, but what about small codes ? Most of "my codes" are no larger then screen can fit so GOTO would be great for my scripts due to no complexity Because its not there i have to create functions and declare variables locally or globally which increase line count by 5% of total code lines (that is my codes, other codes are probably lower then 1%) Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 25, 2010 Share Posted March 25, 2010 If your codes are no larger than a screen then you have absolutely no excuse for wanting a goto. Link to comment Share on other sites More sharing options...
madasraka Posted March 25, 2010 Share Posted March 25, 2010 i have a very big screen Link to comment Share on other sites More sharing options...
MvGulik Posted March 25, 2010 Share Posted March 25, 2010 (edited) whatever Edited February 7, 2011 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
madasraka Posted March 25, 2010 Share Posted March 25, 2010 (edited) MsgBox(0,'','before function') Func name() MsgBox(0,'','function') EndFunc MsgBox(0,'','after functio') Call ("name")is not even close toMsgBox(0,'','before function') :name MsgBox(0,'','function') MsgBox(0,'','after function') GOTO :namePlus "Call" returns function return codes or something but all we need is to jump over something or back to something laugh all u want, my screen is huge. its 20 10 feet away from me and i can still see what i type Edited March 25, 2010 by madasraka Link to comment Share on other sites More sharing options...
MvGulik Posted March 25, 2010 Share Posted March 25, 2010 (edited) whatever Edited February 7, 2011 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
BrettF Posted March 25, 2010 Share Posted March 25, 2010 @Madasraka: Whats the point of using call? @OP: GOTO is useless, and you should forget about it. Remove it from your vocabulary. If you need it to make your code work, then you should either find another hobby/job or sit back and rethink how you are writing this. You should be able to do it easier and better without it. Maybe if you wrote pseudo code to how you want to go about this and what you are actually trying we can help. Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
mireazma Posted March 25, 2010 Author Share Posted March 25, 2010 @ madasraka:I agree with your every post. One little remark, if you allow me: the difference between the two snippets is that in the first code the function is executed only after calling it, not at its declaration.@ Juvigy:I've stated my arguments. If I'm wrong, combat them. @ <all>:- Improper orders from the master are not a reason for firing the servant - Just by being there, Goto doesn't force you to use it, as there are "better" alternatives. Let whoever wants the code obfuscated, use it. On the other hand, it's in the AutoIt creator's right to do whatever finds fit for preserving the language clean.Regarding the code I need, it's a window called "Add Patient Record" which has many editboxes - (more like comboboxes which at "space" press, a window opens with a list to select an item from). Once selected, you press "enter" and the window closes leaving the item filled in the editbox.I want to fill only the required boxes, which have an asterisc (from now on, AB, as opposed to RB - regular box). When I'm done with a box, I want to auto-skip to the next AB. Anytime I deviate from the course and click inside a RB, I want AutoIt to auto-jump to the nearest AB and resume the normal automation. Here is my code (with Goto):expandcollapse popupWinWaitActive("Add Patient Record") :Ltype ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee16") ; jump to "Type" Send("{SPACE}") WinWaitClose("Select type") :Lserial ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee11") ; jump to "Serial" Send("{SPACE}") WinWaitClose("Select serial") :Lnumber ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee1") ; jump to "Number" Send("{SPACE}") WinWaitClose("Select number") :LregNo ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee7") ; jump to "Reg No" Send("{SPACE}") WinWaitClose("Select Reg No") :Lid ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee8") ; jump to "ID" Send("{SPACE}") WinWaitClose("Select ID") :LdateIn ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee3") ; jump to "Date In" Send("{SPACE}") WinWaitClose("Select Date In") :LdateOut ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee4") ; jump to "Date Out" Send("{SPACE}") WinWaitClose("Select Date Out") WinWaitClose("Add Patient Record") :Lrecheck Switch ControlGetFocus("Add Patient Record") Case "WindowsForms10.BUTTON.app.0.2004eee2" Goto, Ltype Case "WindowsForms10.BUTTON.app.0.2004eee5" Goto, Lserial Case "WindowsForms10.BUTTON.app.0.2004eee6" Goto, Lnumber Case "WindowsForms10.BUTTON.app.0.2004eee9" Goto, LregNo Case "WindowsForms10.BUTTON.app.0.2004eee10" Goto, Lid Case "WindowsForms10.BUTTON.app.0.2004eee12" Goto, LdateIn Case "WindowsForms10.BUTTON.app.0.2004eee13" Goto, LdateOut Case Else Goto, Lrecheck EndSwitchCan you find a decent alternative for Goto in this code, to do what I've intended?If you do, you have my respect.(As a note, the comments are redundant as I can simply see the labels but doesn't really matters)I tried with an endlessly looped Switch but I got stuck at the point where the focus had to jump to the next AB. Link to comment Share on other sites More sharing options...
MHz Posted March 25, 2010 Share Posted March 25, 2010 Can you find a decent alternative for Goto in this code, to do what I've intended? Unable to test, but this seems to be a conversion. expandcollapse popupWinWaitActive("Add Patient Record") Ltype() Lserial() Lnumber() LregNo() Lid() LdateIn() LdateOut() Lrecheck() Func Lrecheck() Switch ControlGetFocus("Add Patient Record") Case "WindowsForms10.BUTTON.app.0.2004eee2" Ltype() ContinueCase Case "WindowsForms10.BUTTON.app.0.2004eee5" Lserial() ContinueCase Case "WindowsForms10.BUTTON.app.0.2004eee6" Lnumber() ContinueCase Case "WindowsForms10.BUTTON.app.0.2004eee9" LregNo() ContinueCase Case "WindowsForms10.BUTTON.app.0.2004eee10" Lid() ContinueCase Case "WindowsForms10.BUTTON.app.0.2004eee12" LdateIn() ContinueCase Case "WindowsForms10.BUTTON.app.0.2004eee13" LdateOut() ContinueCase Case Else Lrecheck() EndSwitch EndFunc Exit Func Ltype() ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee16") ; jump to "Type" Send("{SPACE}") WinWaitClose("Select type") EndFunc Func Lserial() ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee11") ; jump to "Serial" Send("{SPACE}") WinWaitClose("Select serial") EndFunc Func Lnumber ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee1") ; jump to "Number" Send("{SPACE}") WinWaitClose("Select number") EndFunc Func LregNo() ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee7") ; jump to "Reg No" Send("{SPACE}") WinWaitClose("Select Reg No") EndFunc Func Lid() ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee8") ; jump to "ID" Send("{SPACE}") WinWaitClose("Select ID") EndFunc Func LdateIn() ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee3") ; jump to "Date In" Send("{SPACE}") WinWaitClose("Select Date In") EndFunc Func LdateOut() ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee4") ; jump to "Date Out" Send("{SPACE}") WinWaitClose("Select Date Out") WinWaitClose("Add Patient Record") EndFunc Link to comment Share on other sites More sharing options...
Beege Posted March 25, 2010 Share Posted March 25, 2010 (edited) Unable to test, but this seems to be a conversion. You just beat me. Mine is pretty simalar, but wouldn't the functions need to call other functions to keep the flow the same? expandcollapse popupWinWaitActive("Add Patient Record") _Ltype() While 1; Lrecheck Switch ControlGetFocus("Add Patient Record") Case "WindowsForms10.BUTTON.app.0.2004eee2" _Ltype() Case "WindowsForms10.BUTTON.app.0.2004eee5" _Lserial() Case "WindowsForms10.BUTTON.app.0.2004eee6" _Lnumber() Case "WindowsForms10.BUTTON.app.0.2004eee9" _LregNo() Case "WindowsForms10.BUTTON.app.0.2004eee10" _Lid() Case "WindowsForms10.BUTTON.app.0.2004eee12" _LdateIn() Case "WindowsForms10.BUTTON.app.0.2004eee13" _LdateOut() Case Else Sleep(200) EndSwitch WEnd Func _Ltype() ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee16") ; jump to "Type" Send("{SPACE}") WinWaitClose("Select type") _Lserial() EndFunc ;==>_Ltype Func _Lserial() ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee11") ; jump to "Serial" Send("{SPACE}") WinWaitClose("Select serial") _Lnumber() EndFunc ;==>_Lserial Func _Lnumber() ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee1") ; jump to "Number" Send("{SPACE}") WinWaitClose("Select number") _LregNo() EndFunc ;==>_Lnumber Func _LregNo() ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee7") ; jump to "Reg No" Send("{SPACE}") WinWaitClose("Select Reg No") _Lid() EndFunc ;==>_LregNo Func _Lid() ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee8") ; jump to "ID" Send("{SPACE}") WinWaitClose("Select ID") _LdateIn() EndFunc ;==>_Lid Func _LdateIn() ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee3") ; jump to "Date In" Send("{SPACE}") WinWaitClose("Select Date In") _LdateOut() EndFunc ;==>_LdateIn Func _LdateOut() ControlFocus("Add Patient Record", "", "WindowsForms10.EDIT.app.0.2004eee4") ; jump to "Date Out" Send("{SPACE}") WinWaitClose("Select Date Out") WinWaitClose("Add Patient Record") EndFunc ;==>_LdateOut Edited March 25, 2010 by Beege Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
MHz Posted March 25, 2010 Share Posted March 25, 2010 You just beat me. Mine is pretty simalar, but wouldn't the functions need to call other functions to keep the flow the same?I am quick sometimes . The labels fall through until the last is reached, then the jump effect happens also with the label fall through effect. The earlier is done by a sequence of function calls and the latter is done with cases using continuecase which starts the jump around all the functions and it should keep going around if I got it right. This is why goto logic can sometimes be like a dog chasing it's own tail as you can lose sight of where the script can be at a given time.Hopefully, your attempt may work as well. Tracing the flow of either attempt is confusing me now . 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