kylomas Posted December 6, 2013 Share Posted December 6, 2013 ? mysterious ... I know, this trips me up every once and a while also... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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 Edit: 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." yes, in this way is explained more clearly. however this ContinueCase it also seems a sort of GoTo spaghetti... I know, this trips me up every once and a while also... ... indeed... 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,It is actually very useful - and not remotely pasta-like. For example, suppose you have "Save" and "Cancel" buttons in a script where there is fair amount of tidying to do on exit. You can run the "Save" code and then immediately move straight into the clear-up code that is run when you press the "Cancel" button - it saves creating yet another function or repeating the same lines of code in both Case blocks: ... Case $cSave ; Save code ContinueCase Case $cCancel ; Clear up code Exit Case ....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...
Gianni Posted December 7, 2013 Share Posted December 7, 2013 PincoPanco, It is actually very useful - and not remotely pasta-like. For example, suppose you have "Save" and "Cancel" buttons in a script where there is fair amount of tidying to do on exit. You can run the "Save" code and then immediately move straight into the clear-up code that is run when you press the "Cancel" button - it saves creating yet another function or repeating the same lines of code in both Case blocks: ... Case $cSave ; Save code ContinueCase Case $cCancel ; Clear up code Exit Case .... M23 Yes, of course, everything it is useful when it is needed, could be equally useful a new command, for example ContinueCheck, making it possible to continue with the next check rather than skip it (in effect, this command does not exist). This is just an "non sense" example to show how the ContinueCheck should flow of course in other situations could have "more sense" and more usefullness ... Case $cOtherStuff ; OtherStuff code .... If $ToBeSaved Then ContinueCase ; ------------+ Else ; | MoreStuff() ; | ContinueCheck ; ----+ | EndIf ; | | Case $cSave ; <-------------+ | ; | ; Save code ; <----------+ ... ContinueCase Case $cCancel ; Clear up code Exit ; ---> Go away Case .... Func MoreStuff() If $x Then $cSave = True Else $cSave = False $cCancel = True EndIf Return EndFunc ;==>MoreStuff 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 7, 2013 Moderators Share Posted December 7, 2013 PincoPanco, making it possible to continue with the next check rather than skip itIn that case use multiple If structures so that you can check all the possibiltiies that you require - the whole point of Switch and Select structures is that only one of the Case statements can ever be actioned. 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...
czardas Posted December 7, 2013 Share Posted December 7, 2013 (edited) Yes, of course, everything it is useful when it is needed, could be equally useful a new command, for example ContinueCheck, making it possible to continue with the next check rather than skip it (in effect, this command does not exist). This is just an "non sense" example to show how the ContinueCheck should flow of course in other situations could have "more sense" and more usefullness ... Case $cOtherStuff ; OtherStuff code .... If $ToBeSaved Then ContinueCase ; ------------+ Else ; | MoreStuff() ; | ContinueCheck ; ----+ | EndIf ; | | Case $cSave ; <-------------+ | ; | ; Save code ; <----------+ ... ContinueCase Case $cCancel ; Clear up code Exit ; ---> Go away Case .... Func MoreStuff() If $x Then $cSave = True Else $cSave = False $cCancel = True EndIf Return EndFunc ;==>MoreStuff Do you mean this? ... Case $cOtherStuff ; OtherStuff code .... If Not $ToBeSaved Then MoreStuff() ContinueCase ; ------------+ | Case $cSave ; | ; | ; Save code ; <----------+ ... ContinueCase Case $cCancel ; Clear up code Exit ; ---> Go away Case .... ; Or do you mean something like this? ... Case $cOtherStuff ; OtherStuff code .... $cSave = True If Not $ToBeSaved Then MoreStuff() If $cSave Then ContinueCase Case $cSave ; Save code ... ContinueCase Case $cCancel ; Clear up code Exit ; ---> Go away Case .... Edited December 7, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Gianni Posted December 7, 2013 Share Posted December 7, 2013 (edited) PincoPanco, ..... the whole point of Switch and Select structures is that only one of the Case statements can ever be actioned. M23 ... the ContinueCase statement breaks this rule, isn't it? in the same way the "ContinueCheck" statement could be allowed Do you mean? ... Case $cOtherStuff ; OtherStuff code .... If Not $ToBeSaved Then MoreStuff() ContinueCase ; ------------+ | Case $cSave ; | ; | ; Save code ; <----------+ ... ContinueCase Case $cCancel ; Clear up code Exit ; ---> Go away Case .... not exactly, in short, I wish I could make the control of the $cSave variable (with Case $cSave) when returning from function instead of "jumping" forward Edited December 7, 2013 by PincoPanco 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...
czardas Posted December 7, 2013 Share Posted December 7, 2013 in short, I wish I could make the control of the $cSave variable (with Case $cSave) when returning from function instead of "jumping" forward Did you look at my edit above? - the second pseudo code example. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 7, 2013 Moderators Share Posted December 7, 2013 PincoPanco,No, I do not believe that ContinueCase breaks the rule that only one Case can be actioned. The whole point of ContinueCase is that you can run code when the relevant Case is not actioned because its condition is not met - as in the "Save"/"Cancel" example I suggested earlier. This looks to be the functional equivalent of the pseudo ContinueCheck code you posted earlier:expandcollapse popup#include <Constants.au3> ; Dummies Global $cSave, $cCancel ; Flags to tell us whether to save and/or cancel Global $fSave = True, $fCancel = False ; Fire just the single case $cControl = 1 Switch $cControl Case 1 ; Run the code and set the save flag if required OtherStuff() ; If the flag was not set then try again If Not $fSave Then ; Run this code and perhaps set Save and Cancel flags MoreStuff() EndIf ; Now continue case in any event ContinueCase Case $cSave MsgBox($MB_SYSTEMMODAL, "Hi", "In Save Case") ; Check the flag = note the default is True so it will fire if actioned directly If $fSave Then ; Save code MsgBox($MB_SYSTEMMODAL, "Hi", "Running Save Code") EndIf ; Now continue case if required - note it will not default to this, only if the flag is set If $fCancel Then ContinueCase EndIf Case $cCancel ; Note this will always fire if actioned directly MsgBox($MB_SYSTEMMODAL, "Hi", "In Cancel Case") ; Clear up code MsgBox($MB_SYSTEMMODAL, "Hi", "Running Cancel Code") Exit EndSwitch Func OtherStuff() If Random(0, 1, 1) Then ConsoleWrite("Saving" & @CRLF) $fSave = True Else $fSave = False EndIf EndFunc Func MoreStuff() If Random(0, 1, 1) Then ConsoleWrite("Saving" & @CRLF) $fSave = True Else $fSave = False EndIf If Random(0, 1, 1) Then ConsoleWrite("Cancelling" & @CRLF) $fCancel = True Else $fCancel = False EndIf EndFunc ;==>MoreStuffAnd now I have wasted enough time on this pointless discussion and so... 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...
Gianni Posted December 7, 2013 Share Posted December 7, 2013 (edited) Thanks czards & Melba23 effort appreciated ...... and sorry for time wasted Edited December 7, 2013 by PincoPanco 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...
czardas Posted December 8, 2013 Share Posted December 8, 2013 PincoPanco - I didn't read the whole thread, but I'm quite sure the answers here are not a waste of time. I just think Melba23 has a lot on his hands, and I'm also grateful for the contributions he makes. GoTo is not evil - it's just somewhat antiquated. To be honest I never thought of using Switch statements to mimic this outdated behaviour. It has some curiousity value, but nothing much beyond that. ; expandcollapse popupGlobal $iPosition = 1, $sOutput = "" While 1 Switch $iPosition Case 1 $sOutput &= "h" Case 2 $sOutput &= "e" Case 3 $sOutput &= "l" $sLen = StringLen($sOutput) If $sLen = 3 Then _GoTo(3) If $sLen = 10 Then _GoTo(8) Case 4 $sOutput &= "o" If StringLen($sOutput) = 5 Then ContinueCase _GoTo(7) Case 5 $sOutput &= " " ContinueCase Case 6 $sOutput &= "w" _GoTo(4) Case 7 $sOutput &= "r" _GoTo(3) Case 8 $sOutput &= "d" ExitLoop ; finished EndSwitch $iPosition += 1 WEnd MsgBox(0, "", $sOutput) Func _GoTo($i) $iPosition = $i -1 EndFunc ; Not quite as efficient as the first AutoIt tutorial. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Gianni Posted December 9, 2013 Share Posted December 9, 2013 HI czardas iterate to check again nice idea thanks! 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...
czardas Posted December 9, 2013 Share Posted December 9, 2013 (edited) I thought it was an interesting exercise. It gives me an impression of how much things have changed over time. There were no real opportunities to study programming when I was in school, but I vaguely remember something about flowcharts in maths. I think every method has its place. I'm not sure where I might use a construct like this, but you never know - it is after all quite easy to follow, if not also a little crazy. Edited December 9, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jchd Posted December 9, 2013 Share Posted December 9, 2013 Everyone reading the part of this thread about Goto and/or posting about it would gain considerable benefit reading Structured Programming with go to statements --a 1974 paper by Donald Knuth (again)-- if they haven't yet. Interestingly enough, this opinion fits nicely with the current news in that it's an early transpose of Mandela's "let's learn to live together in peace". czardas 1 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...
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