Jump to content
Sign in to follow this  
Chobyhy

Two Loops?

Recommended Posts

Chobyhy

Can you run two loops at once? (Example: While)

I'm currently trying to test this code out but its not working properly, infact it would close right after being opened.

Heres the code

#include <GUIConstants.au3>

GUICreate("Test", 500, 300)
GUISetState(@SW_SHOW)

$Menu_File = GUICtrlCreateMenu("&File")
$Test = GUICtrlCreateMenuItem("Test", $Menu_File)
$Switch1 = 0

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $Test
            $Switch1 = 1
    EndSelect
WEnd

While $Switch1 = 1
    $B1 = GUICtrlCreateLabel("Test", 5, 5)
    $B2 = GUICtrlCreateInput("Test2", 20, 20)
    $B3 = GUICtrlCreateButton("Delete", 50, 50)
    If $msg = $B3 Then
    GUICtrlDelete($B1)
    GUICtrlDelete($B2)
    GUICtrlDelete($B3)
    EndIf
WEnd
Edited by Chobyhy

Share this post


Link to post
Share on other sites
Paulie

No, You cannot run two loops simultaneously without running multiple scripts. Autoit is not Multi-threaded, and probably will never be... at least not in the near future.

you can however edit your code like this, and it should work ok:

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $Test
            $Switch1 = 1
    EndSelect
    If $Switch1 = 1 Then
        $B1 = GUICtrlCreateLabel("Test", 5, 5)
        $B2 = GUICtrlCreateInput("Test2", 20, 20)
        $B3 = GUICtrlCreateButton("Delete", 50, 50)
        If $msg = $B3 Then
            GUICtrlDelete($B1)
            GUICtrlDelete($B2)
            GUICtrlDelete($B3)
        EndIf
    EndIf
WEnd

Share this post


Link to post
Share on other sites
Chobyhy

Problem with your version is it will keep creating new CtrlGui as long as var = 1 and its impossible to use the textbox

Share this post


Link to post
Share on other sites
Paulie

Problem with your version is it will keep creating new CtrlGui as long as var = 1 and its impossible to use the textbox

But (Had autoit been able to run 2 loops at once) yours would have been doing the same thing....

I simply was demonstrating how to edit the loops to function as 1, I never tested any of it.

Share this post


Link to post
Share on other sites
PsaltyDS

A classic case for GuiOnEventMode:

#include <GUIConstants.au3>

Global $hGUI, $Menu_File, $Test, $B1, $B2, $B3
Opt("GuiOnEventMode", 1)

GUICreate("Test", 500, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$Menu_File = GUICtrlCreateMenu("&File")
$Test = GUICtrlCreateMenuItem("Test", $Menu_File)
GUICtrlSetOnEvent(-1, "_Menu_Test")
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Func _Menu_Test()
    $B1 = GUICtrlCreateLabel("Test", 5, 5)
    $B2 = GUICtrlCreateInput("Test2", 20, 20)
    $B3 = GUICtrlCreateButton("Delete", 50, 50)
    GUICtrlSetOnEvent(-1, "_Button_Delete")
EndFunc   ;==>_Menu_Test

Func _Button_Delete()
    GUICtrlDelete($B1)
    GUICtrlDelete($B2)
    GUICtrlDelete($B3)
EndFunc   ;==>_Button_Delete

:)


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

Share this post


Link to post
Share on other sites
Chobyhy

Thanks PSaltyDS. Never tried programming it in OnEvent, it looks so confusing...

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.