sqa Posted October 21, 2013 Share Posted October 21, 2013 I have something like 900 lines of code and during its testing I don't want to run all of them every time, but skip some. Let say to execute lines 1-100 and then to skip to 500-... In VB I would use GOTO, but how can I do the same in AutoIt? I can try to comment these lines 101-499, but is there something else? Thanks Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 21, 2013 Moderators Share Posted October 21, 2013 Group your code into Functions, and then call the functions as needed. The help file has an entire section on this. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted November 15, 2013 Moderators Share Posted November 15, 2013 satanttin, the OP is asking about the equivalent to a GOTO statement. Your response makes no sense. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
jchd Posted November 15, 2013 Share Posted November 15, 2013 And deleting own BS post doesn't make more sense. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
NewPlaza Posted November 15, 2013 Share Posted November 15, 2013 I can try to comment these lines 101-499, but is there something else? If you do want the comment these lines you can use these statements #cs MsgBox(0,0,1) MsgBox(0,0,2) #ce Link to comment Share on other sites More sharing options...
Malkey Posted November 17, 2013 Share Posted November 17, 2013 Block Comment or Uncomment If you are using SciTE, you can highlight the code you want to comment out, then go to "Edit" menu and press "Block Comment or Uncomment", or ctrl+Q. Or, you could use "Box Comment". Box Comment (under SciTes "Edit menu) Initally "Box Comment" produced an error message about the variables "comment.box.start.au3", "comment.box.middle.au3", and "comment.box.end.au3", not being declared. For "Box Comment" to work, I had to "Open Global Options File" under SciTe's "Options" menu. And in the SciTeGlobal.properties file change from "strip.trailing.spaces=1" to "strip.trailing.spaces=0" and then saved the file. Then, under SciTe's "Options" menu pressed "Open au3.properties" to open the au3.properties file. In this file I added a space after the equals sign in this line "comment.box.middle.au3=" and then saved this file. Having tested that "Box Comment" now works, I change "strip.trailing.spaces" back to equal "1", and re-saved the SciTeGlobal.properties file. Exit 1 Link to comment Share on other sites More sharing options...
Gianni Posted November 17, 2013 Share Posted November 17, 2013 (edited) You could slightly modify your script (only in test version) and add an "external" Switch construct in this way: Global $GOTO = 0 Switch $GOTO Case 0 ; your whole script goes between these two lines ; ------------ start of your script ------------ MsgBox(0,"", "Good morning") $goto = 150 ; | <-- insert this 2 lines to simulate GOTO 150 ContinueCase ; | this will jump to case 150 ; Case 50 MsgBox(0,"", "Good Afternoon") ; Case 100 MsgBox(0,"", "Good Evening") Case 150 ; | <-- uncomment this to jump here MsgBox(0,"", "What are you still doing up?") ; ------------- end of your script ------------- EndSwitch then move the pair $goto 150 - ContinueCase and Case 150 where you want to jump P.S. just an idea (I post even if I do not like it ) Edited November 17, 2013 by PincoPanco karlkar 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
DraGula Posted December 5, 2013 Share Posted December 5, 2013 Hello there ! I think i'm stupid @PincoPanco, I try to use your example "$GOTO" I want to "switch" between section. Here is a very simple example, but it does not work : Global $GOTO = 0 Switch $GOTO Case 0 If FileExists("C:\Bitlocker.txt") Then $GOTO = 100 Else $GOTO = 200 ContinueCase EndIf Case 100 MsgBox(1, "1", "Case 100") $GOTO = 300 Case 200 MsgBox(1, "1", "Case 200") $GOTO = 400 Exit Case 300 MsgBox(1, "1", "Case 300") Case 400 MsgBox(1, "1", "Case 400") EndSwitch I know this example does not make sens, but for my need the goal is the same. An idea ? Thanks! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 5, 2013 Moderators Share Posted December 5, 2013 DraGula,I strongly suggest you learn how to structure your code so that you do not need appalling workarounds like that. Everyone finds losing GOTO a bit difficult when they first encounter a language that did not use it, but learning how to write code that does not use it is well worth it. Trust me, your code becomes much clearer and easier to debug when you do. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
DraGula Posted December 5, 2013 Share Posted December 5, 2013 DraGula, I strongly suggest you learn how to structure your code so that you do not need appalling workarounds like that. Everyone finds losing GOTO a bit difficult when they first encounter a language that did not use it, but learning how to write code that does not use it is well worth it. Trust me, your code becomes much clearer and easier to debug when you do. M23 Ok... I understanding that GOTO is not a good solution :/ So, I guess the solution for me is to use while and function, right ? DraGula Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 5, 2013 Moderators Share Posted December 5, 2013 DraGula, I guess the solution for me is to use while and function, right ?Exactly. Once you get the hang of it you will wonder how on earth you ever managed to code any other way - your code becomes modular and much easier to debug that a whole mess of GOTO spaghetti. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted December 5, 2013 Moderators Share Posted December 5, 2013 GOTO - the bad practice that just will not die "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Gianni Posted December 5, 2013 Share Posted December 5, 2013 ha "GOTO spaghetti", that's funny I strongly agree with Melba23, (it was just a crazy mental experiment), in addition after testing it, I see that it does not work (because the switch expression is valuated only once at start of construct) sorry DraGula . Anyway, why this other "select" construct does not work as it should? Global $GOTO = 0 Select Case $GOTO = 0 MsgBox(0, "", "case 0 $goto=" & $GOTO) $GOTO = 150 ContinueCase Case $GOTO = 50 MsgBox(0, "", "case 50 $goto=" & $GOTO) ContinueCase Case $GOTO = 100 MsgBox(0, "", "case 100 $goto=" & $GOTO) ContinueCase Case $GOTO = 150 MsgBox(0, "", "case 150 $goto=" & $GOTO) ContinueCase Case Else MsgBox(0, "", "case else $goto=" & $GOTO) EndSelect all the case are executed, ?? why? Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted December 5, 2013 Moderators Share Posted December 5, 2013 (edited) A: You probably should have created your own thread rather than hijacking this one. B: You are telling it to ContinueCase within each statement, what did you expect it to do? Change $GOTO to 49, and you'll see it drops down to the Case Else statement. Edited December 5, 2013 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Gianni Posted December 5, 2013 Share Posted December 5, 2013 A: You probably should have created your own thread rather than hijacking this one. B: You are telling it to ContinueCase within each statement, what did you expect it to do? Change $GOTO to 49, and you'll see it drops down to the Case Else statement. A: many thanks for the advice B: the problem arise if I change the $goto variable within the select Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
MHz Posted December 6, 2013 Share Posted December 6, 2013 There is valid uses for Goto in other languages as for example, functions in command scripts. Just because some make spaghetti code does not mean that everyone does. This example command script calls a label that acts as a function and it can return a value. Goto can also be used to jump past comments. @echo off goto :start :: comments :: comments :start echo testing a function call :function parameter1 echo return value: "%result%" pause goto :eof :function setlocal echo function passed: "%1" set return=%1 endlocal & set result=%return% goto :eof Goto can be used well or it can be made to look like spaghetti. B: the problem arise if I change the $goto variable within the select ContinueCase ignores the following Case statement and runs the code after the Case statement. $case = 1 Select Case $case = 1 ContinueCase Case $case = 2 MsgBox(0, 'test', $case) EndSelect You will see the MsgBox with a 1 in it. Link to comment Share on other sites More sharing options...
Gianni Posted December 6, 2013 Share Posted December 6, 2013 ...... ContinueCase ignores the following Case statement and runs the code after the Case statement. $case = 1 Select Case $case = 1 ContinueCase Case $case = 2 MsgBox(0, 'test', $case) EndSelect You will see the MsgBox with a 1 in it. yes, I have seen, thanks MHzI thought ContinueCase continue to the next Case rather than skip it. Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 6, 2013 Moderators Share Posted December 6, 2013 (edited) PincoPanco, I thought ContinueCase continue to the next Case rather than skip it.It does - but it runs the code within it, not the Case comparison itself. M23Edit: I have amended the Help file text to make this (I hope) clearer: "Normally in a Select or Switch structure, the code within each Case block ends when the next Case statement is encountered. Executing ContinueCase tells AutoIt to stop executing the code within the current Case block and start executing the code within the next Case block. AutoIt does not evaluate the next Case comparison statement - only the code inside the block is run." Edited December 6, 2013 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Gianni Posted December 6, 2013 Share Posted December 6, 2013 PincoPanco, It does - but it runs the code within it, not the Case comparison itself. M23 ? mysterious ... Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 6, 2013 Moderators Share Posted December 6, 2013 PincoPanco,See my edit above. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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