JBassman Posted November 4, 2011 Share Posted November 4, 2011 OK folks, I am working on a GUI for a prog I am building for work. I am trying to pass a gui name to GUISetState to toggle the GUI being visible or not. I have been through the help multiple times, and I have googled everything I can to try and find a solution. Since all that has come to a dead end I have decided to post to you guys to see if you can help me. I am sure it is something simple I am missing, but I just can't find it. Code is below. I have a main gui with buttons that open 3 child guis, and I'd like to have a button on the child guis that I can press to go back to the main gui. If you look in $Child_Button_1 below, you can see how I was trying to track which child was open and close it by creating the gui name of "$ChildX" and passing it to GUISetState, but it doesn't seem to work that way. So I guess my question is can this be done. If so, any help would be greatly appreciated. Thanks, J expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $aWinGetPos, $hChild, $hGUI, $Button_1, $Button_2, $Button_3, $Child_Button_1, $CurrentChild, $Label2, $Label3, $Label4 $hGUI = GUICreate("GUI Example", 600, 400, -1, -1) $Button_1 = GUICtrlCreateButton("Child 1", 10, 10, 115, 25) $Button_2 = GUICtrlCreateButton("Child 2", 130, 10, 115, 25) $Button_3 = GUICtrlCreateButton("Child 3", 250, 10, 115, 25) $Child_Button_1 = GUICtrlCreateButton("Back", 475, 370, 115, 25) GUISetState(@SW_SHOW, $hGUI) $Child1 = GUICreate("", 600, 300, -1, 50, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0xff) $Label2 = GUICtrlCreateLabel("Click to add a new employ to the photo directory.", 130, 55, 234, 17) ;$Child_Button_1 = GUICtrlCreateButton("Back", -1, -1, 115, 25) $Child2 = GUICreate("", 600, 300, -1, 50, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0xFF0000) $Label3 = GUICtrlCreateLabel("Click to change a current employ's info in the photo directory.", 130, 85, 291, 17) ;$Child_Button_1 = GUICtrlCreateButton("Back", -1, -1, 115, 25) $Child3 = GUICreate("", 600, 300, -1, 50, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0x009900) $Label4 = GUICtrlCreateLabel("Click to remove an employ from the photo directory.", 130, 115, 245, 17) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Child_Button_1 Msgbox(0,'Child', 'You pressed the back button on child' & $CurrentChild) $CloseMe = "$Child" & $CurrentChild Msgbox(0,'Child', 'Close: ' & $CloseMe) GUISetState(@SW_HIDE, $CloseMe) ;GUISetState(@SW_HIDE, $Child2) ;GUISetState(@SW_HIDE, $Child3) Case $Button_1 GUISetState(@SW_SHOW, $Child1) GUISetState(@SW_HIDE, $Child2) GUISetState(@SW_HIDE, $Child3) $CurrentChild = 1 Case $Button_2 GUISetState(@SW_SHOW, $Child2) GUISetState(@SW_HIDE, $Child1) GUISetState(@SW_HIDE, $Child3) $CurrentChild = 2 Case $Button_3 GUISetState(@SW_SHOW, $Child3) GUISetState(@SW_HIDE, $Child2) GUISetState(@SW_HIDE, $Child1) $CurrentChild = 3 EndSwitch WEnd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 4, 2011 Moderators Share Posted November 4, 2011 JBassman, Welcome to the AutoIt forum. Alas $CloseMe = "$Child" & $CurrentChild will not work - it just produces a literal string "$Child1". You need to use Execute to get the value of the variable - like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $aWinGetPos, $hChild, $hGUI, $Button_1, $Button_2, $Button_3, $Child_Button_1, $CurrentChild, $Label2, $Label3, $Label4 $hGUI = GUICreate("GUI Example", 600, 400, -1, -1) $Button_1 = GUICtrlCreateButton("Child 1", 10, 10, 115, 25) $Button_2 = GUICtrlCreateButton("Child 2", 130, 10, 115, 25) $Button_3 = GUICtrlCreateButton("Child 3", 250, 10, 115, 25) $Child_Button_1 = GUICtrlCreateButton("Back", 475, 370, 115, 25) GUISetState(@SW_SHOW, $hGUI) $Child1 = GUICreate("", 600, 300, -1, 50, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0xff) $Label2 = GUICtrlCreateLabel("Click to add a new employ to the photo directory.", 130, 55, 234, 17) $Child_Button_1 = GUICtrlCreateButton("Back", 130, 100, 115, 25) GUISetState(@SW_HIDE, $Child1) $Child2 = GUICreate("", 600, 300, -1, 50, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0xFF0000) $Label3 = GUICtrlCreateLabel("Click to change a current employ's info in the photo directory.", 130, 85, 291, 17) GUISetState(@SW_HIDE, $Child2) $Child3 = GUICreate("", 600, 300, -1, 50, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0x009900) $Label4 = GUICtrlCreateLabel("Click to remove an employ from the photo directory.", 130, 115, 245, 17) GUISetState(@SW_HIDE, $Child3) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Child_Button_1 MsgBox(0, 'Child', 'You pressed the back button on child' & $CurrentChild) GUISetState(@SW_HIDE, Execute("$Child" & $CurrentChild)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case $Button_1 GUISetState(@SW_SHOW, $Child1) GUISetState(@SW_HIDE, $Child2) GUISetState(@SW_HIDE, $Child3) $CurrentChild = 1 Case $Button_2 GUISetState(@SW_SHOW, $Child2) GUISetState(@SW_HIDE, $Child1) GUISetState(@SW_HIDE, $Child3) $CurrentChild = 2 Case $Button_3 GUISetState(@SW_SHOW, $Child3) GUISetState(@SW_HIDE, $Child2) GUISetState(@SW_HIDE, $Child1) $CurrentChild = 3 EndSwitch WEndBut as the button can only be pressed when that GUI is visible, why not use the variable $Child1 directly? I see no advantage in going about it the long way round by composing it and using Execute. I hope this helps - please ask if you have any questions. 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...
JBassman Posted November 4, 2011 Author Share Posted November 4, 2011 But as the button can only be pressed when that GUI is visible, why not use the variable Would you mind showing me what you are talking about here? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 4, 2011 Moderators Share Posted November 4, 2011 JBassman, Just use the variable directly like this: GUISetState(@SW_HIDE, $Child1) The variable exists because you have already created the GUI and there is no need to work out which child is visible as the button is only available to be pressed if that particular GUI is visible. 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...
JBassman Posted November 4, 2011 Author Share Posted November 4, 2011 Gotcha! I am sorry...I've been at this for too long and the mind is about fried. I appreciate the help Melba. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 4, 2011 Moderators Share Posted November 4, 2011 JBassman, Glad I could help. 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...
BrewManNH Posted November 4, 2011 Share Posted November 4, 2011 Here's my take on it: I changed a small part of the script to what would need to be changed. MsgBox(0, 'Child', 'You pressed the back button on child' & $CurrentChild) $CloseMe = Eval("Child" & $CurrentChild) ; <<<<<<<<<<< change this line MsgBox(0, 'Child', 'Close: ' & $CloseMe) 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...
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