Jump to content

Loop in a Loop


Recommended Posts

I got a loop in a loop and have to stop one loop when a button is pushed and not sure how to do that.

I hope this example will explain when you click "Stop" it will give you a message box but when you hit "Go" and try and hit "Stop" it won't stop it.

I know why it is not working but not sure of another method or way to do this so I am just using it to show an example.

Actually now that I think of it will my "Do Loop" even work because I got a "While Loop" inside of the "Do Loop" ?

#include <GUIConstants.au3>
$Test = GUICreate("test", 160 , 25)
$Go = GUICtrlCreateButton("Go", 0, 0, 80, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 80, 0, 80, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Go
            $i = 0
            Do
                While 1
                    ToolTip($i , 0 , 0)
                    $i = $i +1
                WEnd
            Until $Stop
        Case $Stop
            MsgBox(0 , "" , "Stop")         
    EndSwitch
WEnd
Edited by JellyFish666
Link to comment
Share on other sites

I got a loop in a loop and have to stop one loop when a button is pushed and not sure how to do that.

I hope this example will explain when you click "Stop" it will give you a message box but when you hit "Go" and try and hit "Stop" it won't stop it.

I know why it is not working but not sure of another method or way to do this so I am just using it to show an example.

Actually now that I think of it will my "Do Loop" even work because I got a "While Loop" inside of the "Do Loop" ?

#include <GUIConstants.au3>
$Test = GUICreate("test", 160 , 25)
$Go = GUICtrlCreateButton("Go", 0, 0, 80, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 80, 0, 80, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Go
            $i = 0
            Do
                While 1
                    ToolTip($i , 0 , 0)
                    $i = $i +1
                WEnd
            Until $Stop
        Case $Stop
            MsgBox(0 , "" , "Stop")         
    EndSwitch
WEnd
first decide what will cause the loop to end. then make it like this

If (you fill this in) Then
ExitLoop
EndIf

this will retun to just the main loop

Link to comment
Share on other sites

#include <GUIConstants.au3>
$Test = GUICreate("test", 160 , 25)
$Go = GUICtrlCreateButton("Go", 0, 0, 80, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 80, 0, 80, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Go
            $i = 0
                While 1
                    If GUIGetMsg() = $Stop Then ExitLoop

                    ToolTip($i , 0 , 0)
                    $i = $i +1
                WEnd
;        Case $Stop
;            MsgBox(0 , "" , "Stop")   
    EndSwitch
WEnd

Also look here

Link to comment
Share on other sites

It cries out for EventMode:

#include <GUIConstants.au3>

Opt("GuiOnEventMode", 1)

Global $iRunFlag = False, $i = 0

$GUI = GUICreate("test", 200 , 50)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$Button = GUICtrlCreateButton("Go", 50, 10, 100, 30)
GUICtrlSetOnEvent(-1, "_ButtonHit")
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
    If $iRunFlag Then
        ToolTip($i)
        $i += 1
    EndIf
WEnd

Func _ButtonHit()
    $iRunFlag = Not $iRunFlag
    If $iRunFlag Then
        ControlSetText($GUI, "", $Button, "STOP")
    Else
        ControlSetText($GUI, "", $Button, "GO")
    EndIf
EndFunc

Func _Quit()
    Exit
EndFunc

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

It cries out for EventMode:

#include <GUIConstants.au3>

Opt("GuiOnEventMode", 1)

Global $iRunFlag = False, $i = 0

$GUI = GUICreate("test", 200 , 50)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$Button = GUICtrlCreateButton("Go", 50, 10, 100, 30)
GUICtrlSetOnEvent(-1, "_ButtonHit")
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
    If $iRunFlag Then
        ToolTip($i)
        $i += 1
    EndIf
WEnd

Func _ButtonHit()
    $iRunFlag = Not $iRunFlag
    If $iRunFlag Then
        ControlSetText($GUI, "", $Button, "STOP")
    Else
        ControlSetText($GUI, "", $Button, "GO")
    EndIf
EndFunc

Func _Quit()
    Exit
EndFunc

:)

Not to me it doesn't. I NEVER use GUIEventMode. Never have and I'm not about to start now. Before you ask, Yes I have tried it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Not to me it doesn't. I NEVER use GUIEventMode. Never have and I'm not about to start now. Before you ask, Yes I have tried it.

Other things GEOSoft has tried and rejected:

1. Any version of Windows with 32bits or more

2. Cell phones

3. Microwave ovens

4. Indoor plumbing

5. Horseless cariages

6. Shoes

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Other things GEOSoft has tried and rejected:

1. Any version of Windows with 32bits or more

2. Cell phones

3. Microwave ovens

4. Indoor plumbing

5. Horseless cariages

6. Shoes

:)

Wrong! I don't reject 1, 4, 5 or 6.

Everybody has their own preferences. In my case I prefer not to use GUIEventMode because I end up having to write a bunch of useless functions to do what can easily be handled in a standard message loop. Beside some of the code I use in the message loop doesn't lend itself well to OnEvent.

I'm not saying that it isn't good for some people though.

If we were to be asked what functions, keywords, options etc. we could do without then that one would be on my list. As a matter of fact the whole Opt/AutoItSetOption thing could go on the chopping block except that I'm pretty sure it would require a lot of code changes in AutoIt.

And I also wouldn't mind geting rid of a few UDF functions and Constants either. Although I usually get around that by copying the functions or Constants that I need directly into my code.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

#include <GUIConstants.au3>
$Test = GUICreate("test", 160 , 25)
$Go = GUICtrlCreateButton("Go", 0, 0, 80, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 80, 0, 80, 25, 0)
GUISetState(@SW_SHOW)
$X = 0
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Go
            $i = 0
            Do
                While NOT ($Msg = $Stop)
                $Msg = GUIGetMsg()
                   ToolTip($i , 0 , 0)
                    $i = $i +1
                WEnd
            Until  $Msg = $Stop
            MsgBox(0 , "" , "Stop1")
            Switch $Msg
            Case $Stop
            MsgBox(0 , "" , "Stop2")
            EndSwitch
    EndSwitch
WEnd

صرح السماء كان هنا

 

Link to comment
Share on other sites

#include <GUIConstants.au3>
$Test = GUICreate("test", 160 , 25)
$Go = GUICtrlCreateButton("Go", 0, 0, 80, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 80, 0, 80, 25, 0)
GUISetState(@SW_SHOW)
$X = 0
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Go
            $i = 0
            Do
                While NOT ($Msg = $Stop)
                $Msg = GUIGetMsg()
                   ToolTip($i , 0 , 0)
                    $i = $i +1
                WEnd
            Until  $Msg = $Stop
            MsgBox(0 , "" , "Stop1")
            Switch $Msg
            Case $Stop
            MsgBox(0 , "" , "Stop2")
            EndSwitch
    EndSwitch
WEnd
Aw, cool I haven't ran it but looks like that answered my question you can :) Edited by JellyFish666
Link to comment
Share on other sites

Aw, cool I haven't ran it but looks like that answered my question you can :)

#include <GUIConstants.au3>
$Test = GUICreate("test", 160 , 25)
$Go = GUICtrlCreateButton("Go", 0, 0, 80, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 80, 0, 80, 25, 0)
GUISetState(@SW_SHOW)
$i1 = 0
While 1
    $Msg = GUIGetMsg()
    $L = "LOOP1"
    $i1 = $i1 + 1
    ToolTip($L & @CRLF & $i1 , 0 , 0)
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Go
            $i2 = 0
            $i3 = 0
            Do
                $L = "LOOP2"
                $i2 = $i2 +1
                ToolTip($L & @CRLF & $i2 , 0 , 0)
                While NOT ($Msg = $Stop) AND $L = "LOOP2"
                $Msg = GUIGetMsg() 
                    $i3 = $i3 +1
                $L = "LOOP3"
                TrayTip($L , $i3 ,0)
                WEnd
            Until  $Msg = $Stop 
        Switch $Msg
        Case $Stop
            MsgBox(0 , "" , "Stop LOOP2 IN " & $i2 & @CRLF & "Stop LOOP3 IN " & $i3)
        EndSwitch           
        Case $Stop
        MsgBox(0 , "" , "Stop LOOP1 IN " & $i1)
    EndSwitch
WEnd

صرح السماء كان هنا

 

Link to comment
Share on other sites

#include <GUIConstants.au3>
$Test = GUICreate("test", 160 , 25)
$Go = GUICtrlCreateButton("Go", 0, 0, 80, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 80, 0, 80, 25, 0)
GUISetState(@SW_SHOW)
$i1 = 0
While 1
    $Msg = GUIGetMsg()
    $L = "LOOP1"
    $i1 = $i1 + 1
    ToolTip($L & @CRLF & $i1 , 0 , 0)
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Go
            $i2 = 0
            $i3 = 0
            Do
                $L = "LOOP2"
                $i2 = $i2 +1
                ToolTip($L & @CRLF & $i2 , 0 , 0)
                While NOT ($Msg = $Stop) AND $L = "LOOP2"
                $Msg = GUIGetMsg() 
                    $i3 = $i3 +1
                $L = "LOOP3"
                TrayTip($L , $i3 ,0)
                WEnd
            Until  $Msg = $Stop 
        Switch $Msg
        Case $Stop
            MsgBox(0 , "" , "Stop LOOP2 IN " & $i2 & @CRLF & "Stop LOOP3 IN " & $i3)
        EndSwitch           
        Case $Stop
        MsgBox(0 , "" , "Stop LOOP1 IN " & $i1)
    EndSwitch
WEnd
haha your awesome ill remember that I sort of feel bad for making you write the code hope it wasn't to much trouble I was just wondering if it was possible with Autoit but now I know it is thanks for sharing your great knowledge with me and hopefully others :)
Link to comment
Share on other sites

haha your awesome ill remember that I sort of feel bad for making you write the code hope it wasn't to much trouble I was just wondering if it was possible with Autoit but now I know it is thanks for sharing your great knowledge with me and hopefully others ;)

thanks dear and u r welcome any time ... :)

صرح السماء كان هنا

 

Link to comment
Share on other sites

from what i know this could be dangoruous, not saying you would use it that way, but i however made a similar script to make an endless array and write hundeds of thousands of files on a cirtual pc, and when stop was pressed all files where ran and the array was doubled, so im saying i fyou are doing somethign like this, it wouldent be wise to release it anywhere, because if so, autoit fans would kill you for getting autoit flagged

Spoiler

Admin Of:http://notmyspace.info [Under Development, looking for volunteers to help improve]http://PSNetCards.co.ukhttp://ZacnAndLindsey.com [Under development, not quite sure what to do with it yet]http://revelm.com------------------------------------Radio Streams:http://75.185.53.88:8000 [128kb/s 44kHz]http://75.185.53.88:8002 [22kb/s 22kHz](works on mobile phones)-----------------------------------My Server:Owned By: http://jumpline.comIP:66.84.19.220Bandwidth:200GBStorage Space:1TBNetwork Connection: 1GB/S[up and down]Operating System: Red Hat LinuxInstalled Apps:Webmail, phpBB, Majordomo, phpMyAdmin, MySQL, Active Server Pages, FrontPage Extensions 2002, GraphicsMagick, Mod Perl, Perl, PHP: Hypertext Preprocessor, Python(want cheap good webhosting, or need a place to park your domain? contact me)-----------------------------------

 

Link to comment
Share on other sites

from what i know this could be dangoruous, not saying you would use it that way, but i however made a similar script to make an endless array and write hundeds of thousands of files on a cirtual pc, and when stop was pressed all files where ran and the array was doubled, so im saying i fyou are doing somethign like this, it wouldent be wise to release it anywhere, because if so, autoit fans would kill you for getting autoit flagged

I understand but as much as it is dangerous it is also useful but if people wanted to screw with people there are much easier ways but I am not going to name them but really I don't need that function right now but I was wondering if it was possible and now thanks to all of you one of my projects is completed.

You always have to ask yourself when your writing a computer language should I add it since it would be useful or should I just not put it in because it could be dangerous, but yes I understand were you are coming from and don't worry.

Edited by JellyFish666
Link to comment
Share on other sites

lol, i know there are more efficient ways, i was just saying that i hope you where not thinking of doing so. because even though there are better ways, autoit can do the job, very quickly based on my tests

Spoiler

Admin Of:http://notmyspace.info [Under Development, looking for volunteers to help improve]http://PSNetCards.co.ukhttp://ZacnAndLindsey.com [Under development, not quite sure what to do with it yet]http://revelm.com------------------------------------Radio Streams:http://75.185.53.88:8000 [128kb/s 44kHz]http://75.185.53.88:8002 [22kb/s 22kHz](works on mobile phones)-----------------------------------My Server:Owned By: http://jumpline.comIP:66.84.19.220Bandwidth:200GBStorage Space:1TBNetwork Connection: 1GB/S[up and down]Operating System: Red Hat LinuxInstalled Apps:Webmail, phpBB, Majordomo, phpMyAdmin, MySQL, Active Server Pages, FrontPage Extensions 2002, GraphicsMagick, Mod Perl, Perl, PHP: Hypertext Preprocessor, Python(want cheap good webhosting, or need a place to park your domain? contact me)-----------------------------------

 

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