HockeyFan Posted January 14, 2011 Share Posted January 14, 2011 Hi, I need some assistance with pausing my script in a While/Wend loop...or what ever command is appriopriate...until a GUI window button is pressed when using GUIONEventMode. I've been able to get this to work by removing the GUIOnEventMode option, but I would rather keep the GUIOnEventMode option enabled. Here is the bare bones of my script. What I'm attempting to do is pause the script when the "_PreMessage" function is called until the GUI window "OK" button is clicked. At that point, Id like the script to continue on from there. What is not working is the "_PreMessage" function when clicking the GUI Button, its not recognizing the click event. Any assistance would be most appriciated!! expandcollapse popup;Start script #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("WinTitleMatchMode", 4) Opt("GUIOnEventMode", 1) Opt("TrayIconDebug", 1) $Process1Text = "Microsoft Office configuration" $Process2Text = "Crystal Reports Trusted Sites & Submittal Reports Bar Code Font" $Process3Text = "User Desktop configuration" $Process4Text = "Cisco VPN Client Installation (Laptops only)" $ProcessCompleteText = " - completed!" $UACGUI = GUICreate("", 682, 584, -1, -1, BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE)) GUICtrlSetCursor (-1, 7) $UserConfigGUILabel1 = GUICtrlCreateLabel("Please wait while the following system configurations are being performed as part of your new computer configuration:", 15, 232, 648, 58) GUICtrlSetFont(-1, 16, 400, 0, "Arial Rounded MT Bold") $Process1 = GUICtrlCreateLabel($Process1Text, 90, 300, 550, 34, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 400, 0, "Arial Rounded MT Bold") $Process2 = GUICtrlCreateLabel($Process2Text, 90, 340, 550, 34, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 400, 0, "Arial Rounded MT Bold") $Process3 = GUICtrlCreateLabel($Process3Text, 90, 380, 550, 34, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 400, 0, "Arial Rounded MT Bold") ;$Process4 = GUICtrlCreateLabel($Process4Text, 90, 420, 550, 34, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 400, 0, "Arial Rounded MT Bold") $Label1 = GUICtrlCreateLabel("New Computer Configuration", 24, 168, 630, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 24, 400, 0, "Arial Rounded MT Bold") GUICtrlSetColor(-1, 0x0000FF) $Radio1 = GUICtrlCreateRadio("", 64, 308, 17, 17) $Radio2 = GUICtrlCreateRadio("", 64, 348, 17, 17) $Radio3 = GUICtrlCreateRadio("", 64, 388, 17, 17) ;$Radio4 = GUICtrlCreateRadio("", 64, 428, 17, 17) $Label2 = GUICtrlCreateLabel("Installation complete!", 26, 470, 630, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 24, 400, 0, "Arial Rounded MT Bold") GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetState(-1, $GUI_HIDE) $Button1 = GUICtrlCreateButton("Close", 248, 520, 177, 41, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "Arial Rounded MT Bold") GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetCursor (-1, 0) GUICtrlSetState ($Radio1, $GUI_DISABLE) GUICtrlSetState ($Radio2, $GUI_DISABLE) GUICtrlSetState ($Radio3, $GUI_DISABLE) ;GUICtrlSetState ($Radio4, $GUI_DISABLE) GUISetState(@SW_HIDE, $UACGUI) GUICtrlSetOnEvent($Button1, "_Exit") ;Evalutaion begins $FileCheck = FileExists ("C:\Software\ImageConfig\UserADAccount.txt") Select Case $FileCheck = 1 ;Success ; Case $FileCheck = 0 ;Failure ; EndSelect $UserADAccountFileOpen = FileOpen("C:\Software\ImageConfig\UserADAccount.txt", 0) $UserADAccountFileRead = FileRead($UserADAccountFileOpen) If $UserADAccountFileRead = @UserName Then $RegLogonCountKeyRead = RegRead("HKEY_CURRENT_USER\Software\UserAccountConfig", "LogonCount") Select Case $RegLogonCountKeyRead = "" $RegLogonCountKeyCreate = RegWrite("HKEY_CURRENT_USER\Software\UserAccountConfig", "LogonCount", "REG_SZ", "1") If $RegLogonCountKeyCreate = 1 Then $RegLogonCountKeyRead = 1 Else Call("_CanNotCreateRegKey") Exit EndIf $RegLogonCountKeyIncrimentWrite = RegWrite("HKEY_CURRENT_USER\Software\UserAccountConfig", "LogonCount", "REG_SZ", $RegLogonCountKeyRead + 1) $RegLogonCountKeyIncrimentRead = RegRead("HKEY_CURRENT_USER\Software\UserAccountConfig", "LogonCount") Call("_PreMessage") MsgBox(0,"For Testing Only!", "Call Function returned...Exit Program") ;Do important function Exit Call("_EmailUserConfigLogonCount") Exit Case $RegLogonCountKeyRead = "2" ;Registry Key EXIST ****Second or more time script has been run by user**** Begin Configuration Process Sleep(30000) $PingCount = 1 Call("_PingTest") Call("_Begin") Call("_EmailDellAssetInformation") Call("_EmailUACInstallLog") Call("_DeleteUserConfigRegKey") Case $RegLogonCountKeyRead > "2" $RegLogonCountKeyIncrimentRead = RegRead("HKEY_CURRENT_USER\Software\UserAccountConfig", "LogonCount") Call("_PingTest") Call("_EmailUACRemove") Call("_DeleteUserConfigRegKey") Exit Case Else ; EndSelect Else Exit EndIf While 1 sleep(40) WEnd Func _Begin() WinMinimizeAll() MsgBox(262208, "","Message goes here." & @CRLF & @CRLF & "Thank you!") GUISetState(@SW_SHOW, $UACGUI) Sleep(5000) $StringLength = StringLen(@ComputerName) If $StringLength = 13 Then $AssetType = StringMid(@ComputerName, 6, 1) Else $Question = MsgBox(262180, "", "Is this computer a Laptop?") If $Question = 6 Then $AssetType = "L" Else $AssetType = "W" EndIf EndIf ;Install Files ;Run OfficeConfig.exe Call("_OfficeConfig") ;Process 1 Sleep(3000) ;Run SubmittalReportBarCodeFont.exe ;Process 2 GUICtrlSetState ($Radio1, $GUI_DISABLE) GUICtrlSetState ($Radio2, $GUI_ENABLE) GUICtrlSetColor ($Process1, 0x8a2be2) GUICtrlSetColor ($Process2, 0xff0000) GUICtrlSetState ($Radio2, $GUI_CHECKED) GUICtrlSetData($Process1, $Process1Text & $ProcessCompleteText) Sleep(5000) ;Run Desktop Config Call("_DesktopConfig") ;Process 3 ;Run Cisco VPN configurations ;Process 4 GUICtrlSetState ($Radio1, $GUI_DISABLE) GUICtrlSetState ($Radio2, $GUI_DISABLE) GUICtrlSetState ($Radio3, $GUI_DISABLE) GUICtrlSetColor ($Process1, 0x8a2be2) GUICtrlSetColor ($Process2, 0x8a2be2) GUICtrlSetColor ($Process3, 0x8a2be2) GUICtrlSetData($Process3, $Process3Text & $ProcessCompleteText) If $AssetType = "L" Then GUICtrlSetState ($Radio1, $GUI_DISABLE) GUICtrlSetState ($Radio2, $GUI_DISABLE) GUICtrlSetState ($Radio3, $GUI_DISABLE) GUICtrlSetColor ($Process1, 0x8a2be2) GUICtrlSetColor ($Process2, 0x8a2be2) GUICtrlSetColor ($Process3, 0x8a2be2) Sleep(3000) Else GUICtrlSetState ($Radio1, $GUI_DISABLE) GUICtrlSetState ($Radio2, $GUI_DISABLE) GUICtrlSetState ($Radio3, $GUI_DISABLE) GUICtrlSetColor ($Process1, 0x8a2be2) GUICtrlSetColor ($Process2, 0x8a2be2) GUICtrlSetColor ($Process3, 0x8a2be2) Sleep(3000) EndIf GUICtrlSetState($Label2, $GUI_SHOW) GUICtrlSetState($Button1, $GUI_SHOW) EndFunc Func CloseWindows() $var = WinList() For $i = 1 to $var[0][0] If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then WinKill($var[$i][0]) EndIf Next EndFunc Func IsVisible($handle) If BitAnd( WinGetState($handle), 2 ) Then Return 1 Else Return 0 EndIf EndFunc Func _OfficeConfig() ;Process 1 enabled GUICtrlSetState ($Radio1, $GUI_ENABLE) GUICtrlSetColor ($Process1, 0xff0000) GUICtrlSetState ($Radio1, $GUI_CHECKED) $Skip = 0 $UserFullNameFile = FileOpen("C:\Software\ImageConfig\UserFullName.txt", 0) $UserFullNameRead = FileReadLine($UserFullNameFile) FileClose($UserFullNameFile) $array = StringSplit ($UserFullNameRead, " ") If $UserFullNameRead = "Temp/Volunteer" Then RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo", "UserName", "REG_SZ", @UserName) RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo", "UserInitials", "REG_SZ", "ADA") $Skip = 1 EndIf If $Skip = 0 Then Select Case $array[0] >= 3 $FirstNameLetter = StringLeft ( $array[1], 1) $SecondNameLetter = StringLeft ( $array[2], 1) $ThirdNameLetter = StringLeft ( $array[3], 1) $FirstNameLetterUpper = StringUpper ($FirstNameLetter) $SecondNameLetterUpper = StringUpper ($SecondNameLetter) $ThirdNameLetterUpper = StringUpper ($ThirdNameLetter) $UserInitials = $FirstNameLetterUpper & $SecondNameLetterUpper & $ThirdNameLetterUpper RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo", "UserName", "REG_SZ", $UserFullNameRead) RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo", "UserInitials", "REG_SZ", $UserInitials) Case $array[0] = 2 $FirstNameLetter = StringLeft ( $array[1], 1) $SecondNameLetter = StringLeft ( $array[2], 1) $FirstNameLetterUpper = StringUpper ($FirstNameLetter) $SecondNameLetterUpper = StringUpper ($SecondNameLetter) $UserInitials = $FirstNameLetterUpper & $SecondNameLetterUpper RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo", "UserName", "REG_SZ", $UserFullNameRead) RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo", "UserInitials", "REG_SZ", $UserInitials) EndSelect EndIf EndFunc Func _EmailUACInstallLog() ; EndFunc Func _EmailUACRemove() ; EndFunc Func _EmailUserConfigLogonCount() ; EndFunc Func _EmailDellAssetInformation() ; EndFunc Func _DesktopConfig() Sleep(3000) GUICtrlSetState ($Radio1, $GUI_DISABLE) GUICtrlSetState ($Radio2, $GUI_DISABLE) GUICtrlSetState ($Radio3, $GUI_ENABLE) GUICtrlSetColor ($Process1, 0x8a2be2) GUICtrlSetColor ($Process2, 0x8a2be2) GUICtrlSetColor ($Process3, 0xff0000) GUICtrlSetState ($Radio3, $GUI_CHECKED) GUICtrlSetData($Process2, $Process2Text & $ProcessCompleteText) EndFunc Func _PingTest() ; EndFunc Func _DeleteUserConfigRegKey() ; EndFunc Func Terminate() ; EndFunc Func _Exit() Exit EndFunc Func _NoLogonADAccountFile() $LogonCountFileError = -1 EndFunc Func _CanNotCreateRegKey() ; EndFunc Func _PreMessage() $PreUACNoteForm = GUICreate("", 545, 372, -1, -1, $WS_CLIPSIBLINGS, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE)) GUISetBkColor(0xFFFFFF) $PreUACNoteLabel1 = GUICtrlCreateLabel("Note from the IT Department...", 16, 8, 508, 41, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 22, 800, 0, "Microsoft Sans Serif") GUICtrlSetColor(-1, 0xFF0000) $PreUACNoteLabel2 = GUICtrlCreateLabel("The next time you log into your computer, a configuration script will run to finish configuring your computer." & @CRLF & @CRLF & "When prompted, please make sure you close all programs and any open Windows. (You will need to be connected to XXX's network for the process to complete successfully.)" & @CRLF & @CRLF & "If you have any questions in reference to this message, please call XXXXXXXXXXX at ext. ####.", 16, 64, 508, 190) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) $PreUACNoteButton = GUICtrlCreateButton("OK", 208, 270, 123, 49, $WS_GROUP) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUICtrlSetCursor (-1, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $PreUACNoteButton Exit EndSwitch WEnd EndFunc Link to comment Share on other sites More sharing options...
BrewManNH Posted January 14, 2011 Share Posted January 14, 2011 You're mixing GUIOnEvent mode and message mode, you can't do that. You have to choose one or the other unless you get fancy with the options. Add a GUICtrlSetOnEvent message for the $PreUACNoteButton button and remove the GetGUIMsg from your While...Wend loop. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
HockeyFan Posted January 14, 2011 Author Share Posted January 14, 2011 OK...I put some more thought into this and this is what I've added to the script... GUICtrlSetOnEvent($PreUACNoteButton, "_ClosePreMessage") . . . $Wait = WinWaitNotActive ($PreUACNoteForm, "Note from the IT Department...") Do $Wait = WinWaitNotActive ($PreUACNoteForm, "Note from the IT Department...") Until $Wait = 1 Func _ClosePreMessage() GUISetState(@SW_Hide, $PreUACNoteForm) EndFunc This seems to work for now... Link to comment Share on other sites More sharing options...
HockeyFan Posted January 14, 2011 Author Share Posted January 14, 2011 You're mixing GUIOnEvent mode and message mode, you can't do that. You have to choose one or the other unless you get fancy with the options. Add a GUICtrlSetOnEvent message for the $PreUACNoteButton button and remove the GetGUIMsg from your While...Wend loop.BrewManNH,Thanks for the reply...that's what i was afraid of. I was hopeing someone a heck of a lot smarter than me had some sort of work around. Basically, what you suggested is what I changed...see my previous post. Link to comment Share on other sites More sharing options...
BrewManNH Posted January 14, 2011 Share Posted January 14, 2011 BTW, unless you absolutely need to, you don't need to Call a function you can just reference the function that you want to execute. This: Call("_CanNotCreateRegKey") Can be done like this: _CanNotCreateRegKey() Using Call prevents you from passing variables using ByRef. Just an FYI, either way will work pretty much the same but the second way saves typing If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
HockeyFan Posted January 14, 2011 Author Share Posted January 14, 2011 BTW, unless you absolutely need to, you don't need to Call a function you can just reference the function that you want to execute. This: Call("_CanNotCreateRegKey") Can be done like this: _CanNotCreateRegKey() Using Call prevents you from passing variables using ByRef. Just an FYI, either way will work pretty much the same but the second way saves typing Thanks again...and thanks for the tip! Link to comment Share on other sites More sharing options...
HockeyFan Posted January 14, 2011 Author Share Posted January 14, 2011 (edited) OK...I put some more thought into this and this is what I've added to the script... GUICtrlSetOnEvent($PreUACNoteButton, "_ClosePreMessage") . . . $Wait = WinWaitNotActive ($PreUACNoteForm, "Note from the IT Department...") Do $Wait = WinWaitNotActive ($PreUACNoteForm, "Note from the IT Department...") Until $Wait = 1 Func _ClosePreMessage() GUISetState(@SW_Hide, $PreUACNoteForm) EndFunc This seems to work for now... DOH!!!!! This doesn't work like I entended it to!! If the window looses focus by clicking somewhere else, it ends the do/until loop...not what I expected to happen. Back to the drawing board! Edited January 14, 2011 by HockeyFan Link to comment Share on other sites More sharing options...
HockeyFan Posted January 14, 2011 Author Share Posted January 14, 2011 You're mixing GUIOnEvent mode and message mode, you can't do that. You have to choose one or the other unless you get fancy with the options. Add a GUICtrlSetOnEvent message for the $PreUACNoteButton button and remove the GetGUIMsg from your While...Wend loop.Can the GUIOnEvent mode be turned on and off to switch from the different modes? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 14, 2011 Moderators Share Posted January 14, 2011 HockeyFan,Can the GUIOnEvent mode be turned on and off to switch from the different modes?Yes.......but! If you find yourself feeling the need to do this in the same script then a very loud warning bell should begin sounding and you should start wondering why you have found yourself in this situation. I would strongly suggest that if you do find yourself in this situation to recast your code to get the whole script to work in the one mode. Where changing mode can be useful is with some UDFs. The ExtMsgBox UDF in my sig uses MessageLoop mode - it changes the mode to MessageLoop as it begins and returns to whatever the original script was using as it exits. As it is a blocking function (you cannot return from it without actioning the ExtMsgBox) you cannot do anything with the original script while you are in the UDF, so changing the mode does not cause any problems in this case. Please ask if you have any more questions about this. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
HockeyFan Posted January 14, 2011 Author Share Posted January 14, 2011 HockeyFan, Please ask if you have any more questions about this. M23 Melba23, Thanks for the heads up! I'm at wits end with two scripts attempting to do the same thing...pause the script until a GUI button is pressed. The problem i'm having with the script i'm working on right now is, the function is called, the GUI window is displayed, but the GUIOnEvent associations for the two GUI buttons is not working. Would you mind looking at what I've got to see if you can see any problems? The function that is not working is the "UserNameADAccountVerify" The main body of the script includes the following Opt("GUIOnEventMode", 1) While 1 Sleep(40) ; Idle around WEnd ...Not sure if the first "While/Wend" causes problems with the "While/Wend" that is also in the function call. expandcollapse popupFunc _VerifyYes() MsgBox(0, "Test", "Yes button clicked") GUISetState(@SW_HIDE, $UserNameADAccountVerifyForm) EndFunc Func _VerifyNo() MsgBox(0, "Test", "No button clicked") GUISetState(@SW_HIDE, $UserNameADAccountVerifyForm) GUISetState(@SW_SHOW, $UserNameInputGUI) EndFunc Func UserNameADAccountVerify() $UserNameADAccountVerifyForm = GUICreate("PLEASE VERIFY", 600, 270, -1, -1, 0, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE)) $UserNameADAccountVerifyLabel1 = GUICtrlCreateLabel("Is the User Info typed correctly?", 80, 16, 468, 33, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) $UserNameADAccountVerifyLabel2 = GUICtrlCreateLabel("User Name:", 80, 65, 196, 33, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) $UserNameADAccountVerifyLabel3 = GUICtrlCreateLabel($UserFullname, 283, 65, 284, 33, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xff0000) ;Red $UserNameADAccountVerifyLabel4 = GUICtrlCreateLabel("AD Logon Account:", 80, 108, 196, 33, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) $UserNameADAccountVerifyLabel5 = GUICtrlCreateLabel($ADLoginName, 283, 108, 284, 33, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xff0000) ;Red $UserNameADAccountVerifyButtonYes = GUICtrlCreateButton("Yes", 136, 168, 123, 41, $WS_GROUP) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") $UserNameADAccountVerifyButtonNo = GUICtrlCreateButton("No", 311, 167, 123, 41, $WS_GROUP) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") ;GUISetState(@SW_HIDE) GUISetState(@SW_SHOW) GUICtrlSetOnEvent($UserNameADAccountVerifyButtonYes, "_VerifyYes") GUICtrlSetOnEvent($UserNameADAccountVerifyButtonNo, "_VerifyNo") While 1 Sleep(10) WEnd EndFunc Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 14, 2011 Share Posted January 14, 2011 (edited) Events are queued and ran after each other, they doesn't interrupt each other. If you want to do this with OnEvent then remove the loop from the event. In this situation it might be easier to use MessageLoop like Melba did though. Edited January 14, 2011 by AdmiralAlkex pixelsearch 1 .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 14, 2011 Moderators Share Posted January 14, 2011 HockeyFan,Two While...WEnd loops in an OnEvent script is just asking for trouble. Let me ask a simple question - how do you ever escape from the second loop in the function? Answer - you do not. AutoIt does not like remaining in functions - it prefers returning to the main idle loop. Alas, it is not as easy as you think it might, or indeed should, be to escape from a loop in a function. As an example, look at this:expandcollapse popup#include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Global $fStop = False $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUICtrlCreateButton("Start", 10, 10, 80, 30) GUICtrlSetOnEvent(-1, "_Start") GUICtrlCreateButton("Stop", 10, 50, 80, 30) GUICtrlSetOnEvent(-1, "_Stop") GUISetState() While 1 Sleep(10) WEnd Func _Exit() Exit EndFunc Func _Start() $fTrue = False $iBegin = TimerInit() ConsoleWrite("Starting" & @CRLF) Do Sleep(10) Until $fStop = True Or TimerDiff($iBegin) > 5000 ConsoleWrite("Stopping" & @CRLF) EndFunc Func _Stop() ConsoleWrite("Please Stop" & @CRLF) $fStop = True EndFuncYou might think that you could easily escape because the Stop button would set the flag and so break the loop. But if you try you see that the loop continues until the timer lets it escape (you see the "TimeOut" message) - and only then will you see the "Please Stop!" messages. This is because AutoIt queues events and only actions them after you return from a running function - I suggest you read the Interrupting a running function tutorial in the Wiki which goes into more depth and also explains how to do it. Please ask - once you have read the tutorial - if anything is unclear. Although as I wrote it, I hope that everything will be as clear as crystal! M23 pixelsearch 1  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
HockeyFan Posted January 17, 2011 Author Share Posted January 17, 2011 HockeyFan,Please ask - once you have read the tutorial - if anything is unclear. Although as I wrote it, I hope that everything will be as clear as crystal! M23Melba,Thanks for all of your help! After considering the information you presented, I decided to rework the script(s) so that it falls back to the main idle loop...as it wants to do. It took a bit more work, but in the long run, the script will be better off. Thanks again for all of your advice and assistance!!! 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