dumdum8684 Posted May 23, 2005 Share Posted May 23, 2005 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: expandcollapse popup#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 More sharing options...
sylvanie Posted May 26, 2005 Share Posted May 26, 2005 Hello, You're right, the for loop prevent to interact with other control. You should use "AdlibEnable" to update your progress : expandcollapse popup#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 More sharing options...
dumdum8684 Posted May 26, 2005 Author Share Posted May 26, 2005 (edited) 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 May 26, 2005 by dumdum8684 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now