Leo1906

ContinueCase and RestartCase?

29 posts in this topic

#1 ·  Posted

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

Share this post


Link to post
Share on other sites



#2 ·  Posted

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.

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by Leo1906

Share this post


Link to post
Share on other sites

#4 ·  Posted

@Leo1906 it would help greatly if you actually posted the script, rather than having us guess at your structure ;)


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

#5 ·  Posted

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


 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Nvm

Edited by dmob
Too hasty reply

Share this post


Link to post
Share on other sites

#7 ·  Posted

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.

Share this post


Link to post
Share on other sites

#8 ·  Posted

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.

Share this post


Link to post
Share on other sites

#9 ·  Posted

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

Share this post


Link to post
Share on other sites

#10 ·  Posted

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 .. :/

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by czardas

Share this post


Link to post
Share on other sites

#12 ·  Posted

a similar "tecnique" already used here (again from the good @czardas :))

2 people like this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#13 ·  Posted (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 by czardas

Share this post


Link to post
Share on other sites

#14 ·  Posted

Agree. As you said, it was just a funny mental puzle... :)


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#15 ·  Posted

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

Share this post


Link to post
Share on other sites

#16 ·  Posted

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)

Share this post


Link to post
Share on other sites

#18 ·  Posted

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)

Share this post


Link to post
Share on other sites

#19 ·  Posted (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 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


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

Share this post


Link to post
Share on other sites

#20 ·  Posted (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 by czardas

Share this post


Link to post
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