cappy2112 Posted January 7, 2006 Share Posted January 7, 2006 I've got two functions. THe first one creates a Gui window with 2 controls. The second funciton is just the event handler for the button press. I want to add text to the label in the Gui, based on the events tha occur when the button is pressed. I've added Global $Label_2 outside of both functions, but I can't get the Label to disply the text, after calling GuitCtrilSetData() What am I doing wrong ? opt("GUIOnEventMode", 1) GuiShow() Global $Label_2 Func GuiShow() Local $Button_1 ;Local $Label_2 Local $WindowID #region --- GuiBuilder code Start --- ; Script generated by AutoBuilder 0.5 Prototype If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 $WindowID = GUICreate("MyGUI", 392, 316, (@DesktopWidth - 392) / 2, (@DesktopHeight - 316) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $Button_1 = GUICtrlCreateButton("Browse Destination Directory", 90, 190, 170, 60) $Label_2 = GUICtrlCreateLabel("Label2", 0, 140, 360, 40) GUICtrlSetOnEvent($Button_1, "OnOpenDirectoryBrowser") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() While 1 Sleep(1000) WEnd #endregion --- GuiBuilder generated code End --- EndFunc ;==>GuiShow Func OnOpenDirectoryBrowser() Local $Filter = "All (*.*)" Local $DefaultDir = "C:\Documents and Settings\Tony\My Documents\src\Python\SYNTHS\G2\Automation\Testdumps" Local $SelectedPath = "" Local $szDrive, $szDir, $szFName, $szExt Local $TestPath = "" $SelectedPath = FileOpenDialog("SELECT DESTINATION DIRECTORY", $DefaultDir, $Filter, 8, "PatchBankXXX") $TestPath = _PathSplit ($SelectedPath, $szDrive, $szDir, $szFName, $szExt) _ArrayDisplay($TestPath, "Demo _PathSplit()") GUICtrlSetData($Label_2, $TestPath[1] & $TestPath[2]) EndFunc ;==>OnOpenDirectoryBrowser Link to comment Share on other sites More sharing options...
Valuater Posted January 7, 2006 Share Posted January 7, 2006 i dont have your function _pathsplit() but this works expandcollapse popup#include <GUIConstants.au3> opt("GUIOnEventMode", 1) $WindowID = GUICreate("MyGUI", 392, 316, (@DesktopWidth - 392) / 2, (@DesktopHeight - 316) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $Button_1 = GUICtrlCreateButton("Browse Destination Directory", 110, 190, 170, 60) $Label_2 = GUICtrlCreateLabel("Label2", 10, 140, 360, 40) GUICtrlSetOnEvent($Button_1, "OnOpenDirectoryBrowser") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() While 1 Sleep(20) WEnd Func OnOpenDirectoryBrowser() Local $Filter = "All (*.*)" Local $DefaultDir = "C:\Documents and Settings\Tony\My Documents\src\Python\SYNTHS\G2\Automation\Testdumps" Local $SelectedPath = "" Local $szDrive, $szDir, $szFName, $szExt Local $TestPath = "" $SelectedPath = FileOpenDialog("SELECT DESTINATION DIRECTORY", $DefaultDir, $Filter, 8, "PatchBankXXX") ;$TestPath = _PathSplit ($SelectedPath, $szDrive, $szDir, $szFName, $szExt) ;_ArrayDisplay($TestPath, "Demo _PathSplit()") ;GUICtrlSetData($Label_2, $TestPath[1] & $TestPath[2]) GUICtrlSetData($Label_2, "this is a test"); test EndFunc;==>OnOpenDirectoryBrowser Func OnExit() Exit EndFunc remove my test and the ";" for your function(s) 8) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 7, 2006 Moderators Share Posted January 7, 2006 @Val - _PathSpit is in my Beta Help... (Weird, because I had to write one 2 weeks ago... so I don't know which release it was in (Using .99 now))Also, seems that Valik fixed a bug with it here: http://www.autoitscript.com/forum/index.ph...topic=19927&hl= Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
cappy2112 Posted January 7, 2006 Author Share Posted January 7, 2006 i dont have your function _pathsplit() but this works #include <GUIConstants.au3> opt("GUIOnEventMode", 1) $WindowID = GUICreate("MyGUI", 392, 316, (@DesktopWidth - 392) / 2, (@DesktopHeight - 316) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $Button_1 = GUICtrlCreateButton("Browse Destination Directory", 110, 190, 170, 60) $Label_2 = GUICtrlCreateLabel("Label2", 10, 140, 360, 40) GUICtrlSetOnEvent($Button_1, "OnOpenDirectoryBrowser") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() While 1 Sleep(20) WEnd Func OnOpenDirectoryBrowser() Local $Filter = "All (*.*)" Local $DefaultDir = "C:\Documents and Settings\Tony\My Documents\src\Python\SYNTHS\G2\Automation\Testdumps" Local $SelectedPath = "" Local $szDrive, $szDir, $szFName, $szExt Local $TestPath = "" $SelectedPath = FileOpenDialog("SELECT DESTINATION DIRECTORY", $DefaultDir, $Filter, 8, "PatchBankXXX") ;$TestPath = _PathSplit ($SelectedPath, $szDrive, $szDir, $szFName, $szExt) ;_ArrayDisplay($TestPath, "Demo _PathSplit()") ;GUICtrlSetData($Label_2, $TestPath[1] & $TestPath[2]) GUICtrlSetData($Label_2, "this is a test"); test EndFunc;==>OnOpenDirectoryBrowser Func OnExit() Exit EndFunc remove my test and the ";" for your function(s) 8) I get a runtime error in the OpenDirectoryBrowser() func Variable used without being declared.: It can't see $Label_2 even though it's declared global Link to comment Share on other sites More sharing options...
cappy2112 Posted January 7, 2006 Author Share Posted January 7, 2006 @Val - _PathSpit is in my Beta Help... (Weird, because I had to write one 2 weeks ago... so I don't know which release it was in (Using .99 now))Also, seems that Valik fixed a bug with it here: http://www.autoitscript.com/forum/index.ph...topic=19927&hl=I'm using .99 also- just got it a few days ago.I hope I have the one with the fixed bug in it Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 7, 2006 Moderators Share Posted January 7, 2006 Considering that post I sent you to was today, I doubt it's in your release... but it looks like he supplied some code you can use. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Valik Posted January 7, 2006 Share Posted January 7, 2006 I fixed _PathFull(), not _PathSplit(). Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 7, 2006 Moderators Share Posted January 7, 2006 I fixed _PathFull(), not _PathSplit().Ahh... sorry Valik, I had not used either, and only glanced at it quickly, and then saw this post... Thanks for the clarification. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
cappy2112 Posted January 7, 2006 Author Share Posted January 7, 2006 I get a runtime error in the OpenDirectoryBrowser() funcVariable used without being declared.: It can't see $Label_2 even though it's declared globalDoes anyone have any thoughts why $LAbel_2 can't be seen in the event handler, even though it is declared GLoba? Link to comment Share on other sites More sharing options...
MHz Posted January 8, 2006 Share Posted January 8, 2006 I've got two functions. THe first one creates a Gui window with 2 controls. The second funciton is just the event handler for the button press. I want to add text to the label in the Gui, based on the events tha occur when the button is pressed. I've added Global $Label_2 outside of both functions, but I can't get the Label to disply the text, after calling GuitCtrilSetData() What am I doing wrong ? opt("GUIOnEventMode", 1) GuiShow() Global $Label_2AutoIt will not have seen $Label_2 as being Global at the time that you use GUICtrlSetData($Label_2, $TestPath[1] & $TestPath[2]). You are calling GuiShow() before the declaration of Global $Label_2. Try moving Global $Label_2 to the top of the script before you call GuiShow(). Link to comment Share on other sites More sharing options...
cappy2112 Posted January 8, 2006 Author Share Posted January 8, 2006 AutoIt will not have seen $Label_2 as being Global at the time that you use GUICtrlSetData($Label_2, $TestPath[1] & $TestPath[2]). You are calling GuiShow() before the declaration of Global $Label_2. Try moving Global $Label_2 to the top of the script before you call GuiShow(). Thanks 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