Jump to content
Sign in to follow this  
matumbo

Restart a loop

Recommended Posts

matumbo

Does it exist any function to restart a loop?

probably a stupid question, but I didn't find one in the help files.

Share this post


Link to post
Share on other sites
BrettF
matumbo

This is my whole script, it's a bank simulator.

Made this one just for fun.

#include <GUIConstants.au3>
Dim $1
Dim $2
Dim $3
Dim $Answer
Global $BankAmount
$BankAmount = 1000

guicreate("Options","275","100")
guictrlcreatelabel("What do you want to do?","100","20")

$1 = GUICtrlCreateButton("Deposit","40","60")
$2 = GUICtrlCreateButton("Withdraw","100","60")
$3 = GUICtrlCreateButton("Statement","170","60")
GUISetState (@SW_SHOW)

While True

    $Msg = GUIGetMsg()
    Switch $Msg
    case $GUI_EVENT_CLOSE
        ExitLoop
    case $1
    guicreate("Input","275","100")
        GUICtrlCreateLabel("How much would you like to  deposit?","70","20")
    $Input = GUICtrlCreateInput("","65","40")
    $Button = GUICtrlCreateButton("Send","110","65")
    guisetstate(@SW_SHOW)
    Do
        Sleep(1)
        $Msg2 = GUIGetMsg()
    until $Msg2 = $Button
    $Amount = GUICtrlRead($Input)
    GUICtrlSetData($Input,"")
    $Bankamount = $Bankamount + $Amount
    Msgbox(0,"Money","Money left on Account =" &$BankAmount)
                                                                                                                  ;[b][u]I want it to restart when it's here, close the window and start over.[/u][/b]
    case $2
    ;Haven't finished the script from here yet.
    Case $3
        
    EndSwitch
    WEnd

I don't find a way to use that example here.

Edited by matumbo

Share this post


Link to post
Share on other sites
SadBunny

Do you mean something like

ContinueLoop [level]

Parameters

level [optional] The level of the loop to restart. The default is 1 (meaning the current loop).


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
matumbo

hm, if it does what it sounds like it would do I think it's it.

Thx

Share this post


Link to post
Share on other sites
matumbo

Only one problem I think, when I continue the loop the window remains open, what function should I use to only close the inputbox?

Share this post


Link to post
Share on other sites
SadBunny

Only one problem I think, when I continue the loop the window remains open, what function should I use to only close the inputbox?

You need to point a variable towards the extra GUI you create (the input gui), so you can delete that gui later on just before the loop re-initiates.

I changed only two lines in your code; the two lines that are left-justified. Seems to work for me like this.

#include <GUIConstants.au3>
Dim $1
Dim $2
Dim $3
Dim $Answer
Global $BankAmount
$BankAmount = 1000

GUICreate("Options", "275", "100")
GUICtrlCreateLabel("What do you want to do?", "100", "20")

$1 = GUICtrlCreateButton("Deposit", "40", "60")
$2 = GUICtrlCreateButton("Withdraw", "100", "60")
$3 = GUICtrlCreateButton("Statement", "170", "60")
GUISetState(@SW_SHOW)

While True

    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $1
$GuiInput = GUICreate("Input", "275", "100")
            GUICtrlCreateLabel("How much would you like to  deposit?", "70", "20")
            $Input = GUICtrlCreateInput("", "65", "40")
            $Button = GUICtrlCreateButton("Send", "110", "65")
            GUISetState(@SW_SHOW)
            Do
                Sleep(1)
                $Msg2 = GUIGetMsg()
            Until $Msg2 = $Button
            $Amount = GUICtrlRead($Input)
GUIDelete($GuiInput)
            $BankAmount = $BankAmount + $Amount
            MsgBox(0, "Money", "Money left on Account =" & $BankAmount)
        ;I want it to restart when it's here, close the window and start over.
        Case $2
        ;Haven't finished the script from here yet.
        Case $3

    EndSwitch
WEnd

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
Blue_Drache

Changing the value of the counter variable inside the loop is considered very bad form, honestly.

Why not just nest the loop and test for a condition?

$intFlag = 0
While $intFlag = 0
   $condition = True
   While $condition = True
       ; Some code
       if SomeThing () = Whatever then $condition = False
   Wend
Wend
Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

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
Sign in to follow this  

×