am632 Posted August 22, 2011 Share Posted August 22, 2011 Hi, I have a simple gui with a button which opens a second window, then when you close the 'child gui' it should just go back to the main gui. here is the script... expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #NoTrayIcon #RequireAdmin Opt("GUIOnEventMode", 1) Opt("GUICloseOnESC", 1) Local $Var = False $Form1 = GUICreate("Main", 456, 313, -1, -1) $LABEL = GUICtrlCreateLabel("Child Window Has not been opened", 80, 40, 310, 28) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseApplication") ;Buttons $BUTTON_CHILD = GUICtrlCreateButton("Child", 184, 144, 75, 25) GUICtrlSetOnEvent($BUTTON_CHILD, "_Begin_Open_Function") While 1 Sleep(0) If $Var Then _Open_Function() EndIf WEnd ;Close Func Func _CloseApplication() Exit EndFunc ;Child Window Func Func _Begin_Open_Function() $Var = True EndFunc Func _Open_Function() $Var = False Opt("GUIOnEventMode", 1) Opt("GUICloseOnESC", 1) GUISetState(@SW_DISABLE, $Form1) $FormChild = GUICreate("Child", 320, 200, -1, -1) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) GUISetState(@SW_SHOW, $FormChild) GUISetOnEvent($GUI_EVENT_CLOSE, "_Close_Child_Window") EndFunc ;Close Child Window Func _Close_Child_Window() GUISetState(@SW_ENABLE, $Form1) GUIDelete($FormChild) EndFunc What it's doing is when you close the child gui it says "$FormChild variable being used without being declaired" and I cant see why its doing this. Can anyone tell me please? Thanks Link to comment Share on other sites More sharing options...
czardas Posted August 22, 2011 Share Posted August 22, 2011 (edited) I made one or two changes to your code.expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #NoTrayIcon #RequireAdmin Opt("GUIOnEventMode", 1) Opt("GUICloseOnESC", 1) Global $FormChild, $Var = False $Form1 = GUICreate("Main", 456, 313, -1, -1) $LABEL = GUICtrlCreateLabel("Child Window Has not been opened", 80, 40, 310, 28) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) ;Buttons $BUTTON_CHILD = GUICtrlCreateButton("Child", 184, 144, 75, 25) GUISetState(@SW_SHOW) GUICtrlSetOnEvent($BUTTON_CHILD, "_Begin_Open_Function") GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseApplication") While 1 Sleep(0) If $Var Then _Open_Function() EndIf WEnd ;Close Func Func _CloseApplication() Exit EndFunc ;Child Window Func Func _Begin_Open_Function() $Var = True EndFunc Func _Open_Function() ;Opt("GUIOnEventMode", 1) ;Opt("GUICloseOnESC", 1) GUISetState(@SW_DISABLE, $Form1) $FormChild = GUICreate("Child", 320, 200, -1, -1) GUICtrlSetFont($FormChild, 14, 400, 0, "MS Sans Serif") GUICtrlSetColor($FormChild, 0x000000) GUISetState(@SW_SHOW, $FormChild) GUISetOnEvent($GUI_EVENT_CLOSE, "_Close_Child_Window") $Var = False EndFunc ;Close Child Window Func _Close_Child_Window() GUISetState(@SW_ENABLE, $Form1) GUIDelete($FormChild) GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseApplication") EndFuncYou should look at the excellent examples by Melba23 in the Wiki. => Managing Multiple GUIs. Edited August 22, 2011 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 22, 2011 Moderators Share Posted August 22, 2011 am632,The $FormChild variable is only declared in the _Open_Function function when it is created. As you do not specify a scope, AutoIt defaults to the Local scope and the variable is invisible to any other function in the script - so when you try to access it in the _Close_Child_Window function, you get the error. Solution: add the $FormChild variable as Global at the top of your script. By the way, the Local $Var = False is automatically recast as all variables in the main script are Global in scope. And you do not need to repeat the Opt lines in the _Open_Function function - the initial ones are valid for the whole script. 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...
am632 Posted August 22, 2011 Author Share Posted August 22, 2011 Thanks both for your help, I understand what your saying melba thanks for explaining Link to comment Share on other sites More sharing options...
czardas Posted August 22, 2011 Share Posted August 22, 2011 Make sure you study the wiki article I mentioned. I learned so much from reading that article. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 22, 2011 Moderators Share Posted August 22, 2011 czardas, Delighted someone finds it useful. 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...
czardas Posted August 22, 2011 Share Posted August 22, 2011 (edited) czardas,Delighted someone finds it useful. M23No need to feel embarrassed about it. I'm not the only one to have benefited from your experience and knowledge. Just keep it up, and thanks for sharing it with us. Edited August 22, 2011 by czardas operator64 ArrayWorkshop 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