Jump to content

For loop problem...


Jester009
 Share

Recommended Posts

Hi,

I'm trying to do the following but I can't get it working

There are three buttons in my gui. When the 1st button is pressed I want to start a loop. Inside the loop when the 2nd button is pressed I want to execute a certain piece of code and when the 3rd button is pressed I need to execute another piece of code.

But I'm unable to get this working :) Can anybody help me with this? Example would be really helpful.. I'm kinda new to Autoit

Thanks

Jester009

Link to comment
Share on other sites

This is a messy way of doing it.

GuiCreate('Testing', 300, 100) 

$buttonOne = GuiCtrlCreateButton('First', 0, 0, 100, 30) 
$buttonTwo = GuiCtrlCreateButton('Second', 100, 0, 100, 30) 
$buttonThree = GuiCtrlCreateButton('Third', 200, 0, 100, 30) 

GuiSetState() 

While 1 
    Switch GuiGetMsg() 
        Case $buttonOne 
            GuiCtrlCreateLabel('Here', 0, 35)
            
            While 1 
                Switch GuiGetMsg() 
                    Case $buttonTwo 
                        GuiCtrlCreateLabel('Here', 100, 35)
                        
                        While 1 
                            Switch GuiGetMsg() 
                                Case $buttonThree 
                                    GuiCtrlCreateLabel('Here', 200, 35) 
                                    Sleep(1000) 
                                    Exit
                                Case -3 
                                    Exit
                            EndSwitch 
                        WEnd 
                    Case -3 
                        Exit
                EndSwitch 
            WEnd 
        Case -3 
            Exit
    EndSwitch 
WEnd

This is how I would to it

#include <GUIConstants.au3>

GuiCreate('Testing', 300, 100) 

$buttonOne = GuiCtrlCreateButton('First', 0, 0, 100, 30) 
$buttonTwo = GuiCtrlCreateButton('Second', 100, 0, 100, 30) 
    GuiCtrlSetState($buttonTwo, $GUI_DISABLE)
$buttonThree = GuiCtrlCreateButton('Third', 200, 0, 100, 30) 
    GuiCtrlSetState($buttonThree, $GUI_DISABLE)

GuiSetState() 

While 1 
    Switch GuiGetMsg() 
        Case $buttonOne 
            GuiCtrlCreateLabel('Here', 0, 35)
            GuiCtrlSetState($buttonTwo, $GUI_ENABLE)
            GuiCtrlSetState($buttonOne, $GUI_DISABLE)
        Case $buttonTwo 
            GuiCtrlCreateLabel('Here', 100, 35)
            GuiCtrlSetState($buttonTwo, $GUI_DISABLE)
            GuiCtrlSetState($buttonThree, $GUI_ENABLE)
        Case $buttonThree 
            GuiCtrlCreateLabel('Here', 200, 35) 
            GuiCtrlSetState($buttonThree, $GUI_DISABLE)
            Sleep(1000) 
            Exit
        Case $GUI_EVENT_CLOSE 
            Exit
    EndSwitch 
WEnd
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

This the code...

#include <GUIConstants.au3>

$Form1 = GUICreate("Form1", 392, 132, 193, 120)
$Button1 = GUICtrlCreateButton("Button1", 48, 48, 57, 25, 0)
$Button2 = GUICtrlCreateButton("Button2", 160, 48, 65, 25, 0)
    GUICtrlSetState($Button2, $GUI_DISABLE)
$Button3 = GUICtrlCreateButton("Button3", 280, 48, 65, 25, 0)
    GUICtrlSetState($Button3, $GUI_DISABLE)
GUISetState(@SW_SHOW)

Do
    $msg = GUIGetMsg()
    if $msg = $Button1 Then
        MsgBox(0, "Test", "Button1 pressed")
        GUICtrlSetState($Button2, $GUI_ENABLE)
        GUICtrlSetState($Button1, $GUI_DISABLE)
        For $i = 1 to 5
            MsgBox(0, "Test", "About to press Button2")
            If $msg = $Button2 Then
                MsgBox(0, "Test", "Button2 pressed")
                GUICtrlSetState($Button3, $GUI_ENABLE)
                GUICtrlSetState($Button2, $GUI_DISABLE)
            EndIf
            If $msg = $Button3 Then
                MsgBox(0, "Test", "Button3 pressed")
            EndIf
        Next
        EndIf
Until $msg = $GUI_EVENT_CLOSE
Edited by Jester009
Link to comment
Share on other sites

This is the most retarded way of doing it.....try it out...lol...

#include <GUIConstants.au3>

$Form1 = GUICreate("Form1", 392, 132, 193, 120)
$Button1 = GUICtrlCreateButton("Button1", 48, 48, 57, 25, 0)
$Button2 = GUICtrlCreateButton("Button2", 160, 48, 65, 25, 0)
    GUICtrlSetState($Button2, $GUI_DISABLE)
$Button3 = GUICtrlCreateButton("Button3", 280, 48, 65, 25, 0)
    GUICtrlSetState($Button3, $GUI_DISABLE)
GUISetState(@SW_SHOW)

Do
    $msg = GUIGetMsg()
    if $msg = $Button1 Then
      ; MsgBox(0, "Test", "Button1 pressed")
        GUICtrlSetState($Button2, $GUI_ENABLE)
        GUICtrlSetState($Button1, $GUI_DISABLE)
        For $i = 1 to 5000000
          ; MsgBox(0, "Test", "About to press Button2")
          ;ConsoleWrite($i & @CRLF)
           $msg2 = GUIGetMsg()
            If $msg2 = $Button2 Then
               ;MsgBox(0, "Test", "Button2 pressed")
                GUICtrlSetState($Button3, $GUI_ENABLE)
                GUICtrlSetState($Button2, $GUI_DISABLE)
                ExitLoop
                
                
            EndIf
        Next
    EndIf
    
     if $msg = $Button2 Then
        GUICtrlSetState($Button3, $GUI_ENABLE)
                GUICtrlSetState($Button2, $GUI_DISABLE)
                
                For $i = 1 to 5
          ; MsgBox(0, "Test", "About to press Button2")
          ;ConsoleWrite($i & @CRLF)
           $msg3 = GUIGetMsg()
            If $msg3 = $Button3 Then
                MsgBox(0, "Test", "Button2 pressed")
                GUICtrlSetState($Button3, $GUI_DISABLE)
              ; GUICtrlSetState($Button2, $GUI_DISABLE)
            EndIf
        Next
            EndIf


    if $msg = $Button3 Then
      ; MsgBox(0, "Test", "Button1 pressed")
       
        GUICtrlSetState($Button3, $GUI_DISABLE)
        For $i = 1 to 5000000
          ; MsgBox(0, "Test", "About to press Button2")
          ;ConsoleWrite($i & @CRLF)
           $msg4 = GUIGetMsg()
           
           If $msg4=$GUI_EVENT_CLOSE then ExitLoop
        Next
    EndIf
    
         
Until $msg = $GUI_EVENT_CLOSE
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...