Jump to content

Exiting Functions


Recommended Posts

I noticed that while in a for loop (which is inside of a function) you can't go to another function. This is while in OnEvent mode. I was wondering if there was a work around. Here is the code:

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

; GUI
GuiCreate("Sample GUI", 400, 400)
GuiSetIcon(@SystemDir & "\mspaint.exe", 0)
GUISetBkColor (0xE0FFFF)

GUISetOnEvent($GUI_EVENT_CLOSE, "CloseWin")

; CONTEXT MENU
$contextMenu = GuiCtrlCreateContextMenu()
GuiCtrlCreateMenuItem("Context Menu", $contextMenu)
GuiCtrlCreateMenuItem("", $contextMenu);separator
GuiCtrlCreateMenuItem("&Properties", $contextMenu)

; PROGRESS
$progress = GuiCtrlCreateProgress(60, 80, 150, 20)
GuiCtrlSetData(-1, 0)
GuiCtrlCreateLabel("Progress:", 5, 82)

; BUTTON
$startbtn = GuiCtrlCreateButton("Start", 10, 330, 100, 30)
GUICtrlSetOnEvent($startbtn, "StartProg")

; BUTTON
$exitbtn = GuiCtrlCreateButton("Exit", 150, 330, 100, 30)
GUICtrlSetOnEvent($exitbtn, "CloseWin")

; GUI MESSAGE LOOP
GuiSetState(@SW_SHOW)
Dim $i = 0 


While 1
    Sleep(1000)
WEnd




Func StartProg()    
    For $i = 0 to 50 Step 5
    GuiCtrlSetData($progress, $i)
    Sleep(1000)
    Next
    MsgBox(0, "All Done", "Error") 
EndFunc

Func CloseWin()
    MsgBox(0, "Status", "Good-Bye...")
    Exit
EndFunc

I'm not trying to do anything with this program, I'm just getting comfortable with the new GUI commands. Thanks.

-Aaron

Link to comment
Share on other sites

Hello,

You're right, the for loop prevent to interact with other control.

You should use "AdlibEnable" to update your progress :

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

; GUI
GuiCreate("Sample GUI", 400, 400)
GuiSetIcon(@SystemDir & "\mspaint.exe", 0)
GUISetBkColor (0xE0FFFF)

GUISetOnEvent($GUI_EVENT_CLOSE, "CloseWin")

; CONTEXT MENU
$contextMenu = GuiCtrlCreateContextMenu()
GuiCtrlCreateMenuItem("Context Menu", $contextMenu)
GuiCtrlCreateMenuItem("", $contextMenu);separator
GuiCtrlCreateMenuItem("&Properties", $contextMenu)

; PROGRESS
$progress = GuiCtrlCreateProgress(60, 80, 150, 20)
GuiCtrlSetData(-1, 0)
GuiCtrlCreateLabel("Progress:", 5, 82)

; BUTTON
$startbtn = GuiCtrlCreateButton("Start", 10, 330, 100, 30)
GUICtrlSetOnEvent($startbtn, "StartProg")

; BUTTON
$exitbtn = GuiCtrlCreateButton("Exit", 150, 330, 100, 30)
GUICtrlSetOnEvent($exitbtn, "CloseWin")

; GUI MESSAGE LOOP
GuiSetState(@SW_SHOW)
Dim $i = 0 


While 1
    Sleep(1000)
WEnd




Func StartProg()
    AdlibEnable("progress",1000)
    GUICtrlSetState($startbtn,$GUI_DISABLE)
EndFunc

Func progress()
    If $i<=50 Then
        GuiCtrlSetData($progress, $i)
        $i=$i+5
    Else
        MsgBox(0, "All Done", "OK") 
        $i=0
        GUICtrlSetState($startbtn,$GUI_ENABLE)
        AdlibDisable()
    EndIf
EndFunc

Func CloseWin()
    MsgBox(0, "Status", "Good-Bye...")
    Exit
EndFunc
Link to comment
Share on other sites

On another note this also works. I was messing with it more.

; GUI MESSAGE LOOP
GuiSetState(@SW_SHOW)
Dim $i = 0, $flag = 0

While 1
    Sleep(1000)
    If $flag == 1 Then
        For $i = 0 to 50 Step 5
            GuiCtrlSetData($progress, $i)
            Sleep(1000)
        Next
        
        MsgBox(0, "All Done", "Error") 
        $flag = 0
    EndIf
    
    
WEnd




Func StartProg()    
    $flag = 1
    
EndFunc

Func CloseWin()
    MsgBox(0, "Status", "Good-Bye...")
    Exit
EndFunc

Is this good coding or should I use the way sylvanie said?

Thanks,

-Aaron

Edited by dumdum8684
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...