Leo1906 Posted October 7, 2016 Share Posted October 7, 2016 Hello there, I got a quick question .. i know that there is something like ContinueCase, which jumps to the next case and executes it. But is there also something like RestartCase? Let me explain you why I need something like this. My script hase a Select-Case structure as main part and in one of those cases I am catching an @error. When this happens I want the script to start the Case aggain. I can't use a while structure ore similar, because this would trap the script in it and the other cases can't be executed in time .. So.. simple question: is there something like this, or is there a workaround for this? Other structures got this feature. For example: ContinueLoop (which starts the loop at the beginning) Thanks for your help Link to comment Share on other sites More sharing options...
AutoBert Posted October 7, 2016 Share Posted October 7, 2016 1 minute ago, Leo1906 said: i know that there is something like ContinueCase, which jumps to the next case and executes it. But is there also something like RestartCase? I can't find a func named RestartCase in helpfile. Please make a runable reproducer script showing the issue. Link to comment Share on other sites More sharing options...
Leo1906 Posted October 7, 2016 Author Share Posted October 7, 2016 (edited) Hehe yeah I can't find it either, but I need someting like this. I made the name up. I just want to know if there's a command that restarts a Case at the beginning of the case .. I don't have a running script right know to demonstrate the need of it .. :/ Edit: or can I just abort the case somehow? So that it switches directly to the Select back aggain and checks for the cases to be valid? Like the Break command in other languages Edited October 7, 2016 by Leo1906 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 7, 2016 Moderators Share Posted October 7, 2016 @Leo1906 it would help greatly if you actually posted the script, rather than having us guess at your structure "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...
Somerset Posted October 7, 2016 Share Posted October 7, 2016 20 minutes ago, JLogan3o13 said: @Leo1906 it would help greatly if you actually posted the script, rather than having us guess at your structure Why does that sound like a drinking game? You guess wrong, you have to take a swig. Link to comment Share on other sites More sharing options...
dmob Posted October 7, 2016 Share Posted October 7, 2016 (edited) Nvm Edited October 7, 2016 by dmob Too hasty reply Link to comment Share on other sites More sharing options...
pluto41 Posted October 8, 2016 Share Posted October 8, 2016 HotKeySet ( "a", Quit ) Local $iValue While TRUE $iValue = Random (0, 9, 1) RestartCase () Sleep ( 100 ) WEnd Func RestartCase () Select Case $iValue = 1 ConsoleWrite ( "Value : " & $iValue & @CRLF ) Case $iValue = 7 ConsoleWrite ( "Value : " & $iValue & @CRLF ) EndSelect EndFunc ;==>RestartCase Func Quit () Exit 0 EndFunc ;==>Quit You could put the Select statement it in a While Loop or Do Until. Something like this. Link to comment Share on other sites More sharing options...
Leo1906 Posted October 8, 2016 Author Share Posted October 8, 2016 Well .. I can't explain the problem better than I did and I can't post any sample, because I have no working code right now .. Select Case $test = 1 do blabla .. If @error then RestartCase Else Exit EndIf EndSelect ok, so this is no woking code, but should make it easier to understand. When the Case is true something is happening. If there is an error it should start from the beginning. I don't get what's so hard to understand? All I wanted to know is, if there is something like RestartCase (which I made up right now) which starts the case from the beginning ...? I coouldn't find anything in the helpfile or google. Link to comment Share on other sites More sharing options...
pluto41 Posted October 8, 2016 Share Posted October 8, 2016 While True Select Case $test = 1 do blabla .. If @error then ContinueLoop Else Exit 0 EndIf EndSelect WEnd as Far as i know there isn't something like RestartCase. But like i said you could wrap the Select statement into a Loop. See ContinueLoop () Link to comment Share on other sites More sharing options...
Leo1906 Posted October 8, 2016 Author Share Posted October 8, 2016 Yeah .. it is already in a while loop and I don't think that this would help me :/ i think I just dublicate the case and use a statement that could never be true and than use ContinueCase. So I can be sure that the case would never be executed itself, but if I use ContinueCase the statement won't be checked .. Very strange feature .. I don't know when there's an actual use for it .. Instead of ContinueCase they should have implemented a RestartCase Thank you all for your help. I think that there is no other solution than what I just wrote .. :/ Link to comment Share on other sites More sharing options...
czardas Posted October 8, 2016 Share Posted October 8, 2016 (edited) You could put your Select statement inside a Do... Until loop: similar to some of the suggestions already. Local $bError = False Do Select Case Mod(@SEC, 2) ; blah blah blah ConsoleWrite('blah ') Sleep(20) Case Else $bError = True EndSelect Until $bError ConsoleWrite(@LF) This writes blah (approx every 20 ms) while the current second is odd. Edited October 8, 2016 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Gianni Posted October 8, 2016 Share Posted October 8, 2016 a similar "tecnique" already used here (again from the good @czardas ) czardas and Leo1906 2 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 October 8, 2016 Share Posted October 8, 2016 (edited) @Chimp Bringing back fond memories: that was a fun example for me at the time. It would be better with something like an array of commands rather than a Switch Statement (more modular). Edited October 8, 2016 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Gianni Posted October 9, 2016 Share Posted October 9, 2016 Agree. As you said, it was just a funny mental puzle... 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...
Leo1906 Posted October 9, 2016 Author Share Posted October 9, 2016 17 hours ago, Chimp said: a similar "tecnique" already used here (again from the good @czardas ) Thank you! That is a really good idea how to solve this problem Link to comment Share on other sites More sharing options...
jchd Posted October 10, 2016 Share Posted October 10, 2016 This is the general structure of a state machine. Rewriting @czardas's code without the ugly _GoTo() is exactly that, a state machine: expandcollapse popupLocal $iPosition = 1, $sOutput, $again3 While 1 Select Case $iPosition = 1 $sOutput &= "H" Case $iPosition = 2 $sOutput &= "e" Case $iPosition = 3 $sOutput &= "l" Switch StringLen($sOutput) Case 3 $again3 = True Case 10 $iPosition = 7 EndSwitch Case $again3 $again3 = False $iPosition -= 1 $sOutput &= "l" Case $iPosition = 4 $sOutput &= "o" If StringLen($sOutput) <> 5 Then $iPosition = 6 Case $iPosition = 5 $sOutput &= " " Case $iPosition = 6 $sOutput &= "w" $iPosition = 3 Case $iPosition = 7 $sOutput &= "r" $iPosition = 2 Case $iPosition = 8 $sOutput &= "d" ExitLoop ; finished EndSelect $iPosition += 1 WEnd MsgBox(0, "", $sOutput) 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...
czardas Posted October 10, 2016 Share Posted October 10, 2016 Just like my 1970's programmable Casio calculator. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jchd Posted October 10, 2016 Share Posted October 10, 2016 Yup, but look Ma', no Goto !!! 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...
rcmaehl Posted October 10, 2016 Share Posted October 10, 2016 (edited) 1 hour ago, jchd said: Yup, but look Ma', no Goto !!! Honestly there's basically no use of GOTO that can't be solved with the existing other programming keywords... but the same could be said for Select/Switch/Case - as If can be used While - as Do followed by If can be used Do - as While followed by if at the end of the code loop can be used For - as Do / While can be used And a bunch of other stuff! Edited October 10, 2016 by rcmaehl My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.My Projects WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
czardas Posted October 10, 2016 Share Posted October 10, 2016 (edited) If a real world system involves a goto process, then there's a good argument for simulating the same process in code, if for no other reason than to associate the real world with the virtual representation. On the other hand; if using another approach is better, for a different reason, then the above does not necessarily apply. Edited October 10, 2016 by czardas operator64 ArrayWorkshop 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