Jump to content

ContinueCase and RestartCase?


Recommended Posts

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

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

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 by Leo1906
Link to comment
Share on other sites

  • Moderators

@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

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

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

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

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 .. :D
Instead of ContinueCase they should have implemented a RestartCase :P 

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

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 by czardas
Link to comment
Share on other sites

This is the general structure of a state machine. Rewriting @czardas's code without the ugly _GoTo() is exactly that, a state machine:

Local $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 here
RegExp tutorial: enough to get started
PCRE 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

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 here
RegExp tutorial: enough to get started
PCRE 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

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 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

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

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 by czardas
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...