cvocvo Posted June 14, 2010 Share Posted June 14, 2010 (edited) So I'm working on a simple menu chooser with three buttons. Two of the buttons (XP and Vista7) hide the window and continue on. A third button is supposed to hide the window, and load a new window with two buttons (Go back and Exit). I want Go back to re-open the original window with three buttons, and I want exit to close the program. My problem is that the two buttons (Go back and Exit) do not work correctly. expandcollapse popup$FormChooseOS = GUICreate("Choose the Operating System", 500, 350, 334, 140, $DS_MODALFRAME) $Label1 = GUICtrlCreateLabel("Choose the Operating System", 35, 24, 430, 40) GUICtrlSetFont($Label1, 24, 400, 0, "MS Sans Serif") $XP = GUICtrlCreateButton("Windows XP/XPe/Embedded Standard", 150, 88, 200, 65, 0) GUICtrlSetOnEvent($XP, "XPClick") $Vista7 = GUICtrlCreateButton("Windows Vista/7/Embedded 7", 150, 160, 200, 65, 0) GUICtrlSetOnEvent($Vista7, "Vista7Click") $Other = GUICtrlCreateButton("Other", 150, 232, 200, 65, 0) GUICtrlSetOnEvent($Other, "OtherClick") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func OtherClick() Opt("GUIOnEventMode", 1) GUISetState(@SW_HIDE,"Choose the Operating System") $FormUnsupported = GUICreate("Unsupported", 283, 130, 192, 124, $DS_MODALFRAME) $TextBox = GUICtrlCreateLabel("Sorry, we do not support any other operating systems.", 16, 16, 256, 17) $GoBack = GUICtrlCreateButton("Go Back", 16, 48, 105, 65, 0) GUICtrlSetOnEvent($GoBack, "GoBackClick") $Exit = GUICtrlCreateButton("Exit", 160, 48, 105, 65, 0) GUICtrlSetOnEvent($Exit, "ExitClick") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd EndFunc Func ExitClick() MsgBox(0,"","") Exit EndFunc Func GoBackClick() GUISetState(@SW_HIDE, "Unsupported") GUISetState(@SW_SHOW, "Choose the Operating System") MsgBox(0,"","") EndFunc Func Vista7Click() $OSVersion = "XP" GUISetState(@SW_HIDE) Continue() EndFunc Func XPClick() $OSVersion = "XP" GUISetState(@SW_HIDE) Analyze() EndFunc I originally had the functions 'ExitClick()' and 'GoBackClick()' inside the 'OtherClick() function, but I was getting errors and it wouldn't load. Anyone have any advice on how I could get this to work? Edited June 14, 2010 by cvocvo Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 14, 2010 Moderators Share Posted June 14, 2010 cvocvo,Just the one problems with the code which stopped it working as you wished:You had an unnecessary loop in function OtherClick(). This infinite loop blocked the whole script as there was no way to get out of it! Remember you only need ONE loop in an OnEvent mode script. A couple of other points:- 1. You need to delare the handle of the "Unsupported" window as a Global variable. You had it declared within function OtherClick() and so it was Local in scope. This means that function GoBackClick() would not be able to access it unless we declare it as Global initially.- 2. You need to delete the "Unsupported" GUI when you go back - if you press the "Other" button you would create another GUI and waste resources. Here is a modified version of your script:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) $FormUnsupported = 9999 $FormChooseOS = GUICreate("Choose the Operating System", 500, 350, 334, 140, $DS_MODALFRAME) $Label1 = GUICtrlCreateLabel($FormChooseOS, 35, 24, 430, 40) GUICtrlSetFont($Label1, 24, 400, 0, "MS Sans Serif") $XP = GUICtrlCreateButton("Windows XP/XPe/Embedded Standard", 150, 88, 200, 65, 0) GUICtrlSetOnEvent($XP, "XPClick") $Vista7 = GUICtrlCreateButton("Windows Vista/7/Embedded 7", 150, 160, 200, 65, 0) GUICtrlSetOnEvent($Vista7, "Vista7Click") $Other = GUICtrlCreateButton("Other", 150, 232, 200, 65, 0) GUICtrlSetOnEvent($Other, "OtherClick") GUISetState(@SW_SHOW) While 1 Sleep(10) ; 10 is enough WEnd Func OtherClick() GUISetState(@SW_HIDE, $FormChooseOS) $FormUnsupported = GUICreate("Unsupported", 283, 130, 192, 124, $DS_MODALFRAME) $TextBox = GUICtrlCreateLabel("Sorry, we do not support any other operating systems.", 16, 16, 256, 17) $GoBack = GUICtrlCreateButton("Go Back", 16, 48, 105, 65, 0) GUICtrlSetOnEvent($GoBack, "GoBackClick") $Exit = GUICtrlCreateButton("Exit", 160, 48, 105, 65, 0) GUICtrlSetOnEvent($Exit, "ExitClick") GUISetState(@SW_SHOW) EndFunc ;==>OtherClick Func ExitClick() MsgBox(0, "", "Exiting") Exit EndFunc ;==>ExitClick Func GoBackClick() GUIDelete($FormUnsupported) GUISetState(@SW_SHOW, $FormChooseOS) MsgBox(0, "", "Gone Back") EndFunc ;==>GoBackClick Func Vista7Click() $OSVersion = "XP" GUISetState(@SW_HIDE) ;Continue() EndFunc ;==>Vista7Click Func XPClick() $OSVersion = "XP" GUISetState(@SW_HIDE) ;Analyze() EndFunc ;==>XPClickI hope that is all clear. 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...
cvocvo Posted June 14, 2010 Author Share Posted June 14, 2010 Thank you very much, I appreciate the help. I am just learning how to use autoit and every bit of knowledge helps me. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 14, 2010 Moderators Share Posted June 14, 2010 cvocvo, My pleasure - that is what we are here for! 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...
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