cmattb Posted January 7, 2009 Share Posted January 7, 2009 (edited) So im having a problem calling another function from a child GUI. For some reason, $button2 does not want to do anything. As far as I can tell, I have everything correct, but its probably something dumb that I missed. #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) Opt("TrayIconDebug",1) Global $gui1 = GUICreate("GUI numer one", 200, 200) Global $button1 = GUICtrlCreateButton("Go GUI #2!", 50,50) GUICtrlSetOnEvent($button1, "gui2") GUISetState(@SW_SHOW) While 1 sleep(200) WEnd Func gui2() Global $gui2 = GUICreate("GUI numer two", 150, 150) Global $button2 = GUICtrlCreateButton("msg box", 20,50) GUICtrlSetOnEvent($button2, "mbox") GUISetState(@SW_SHOW) While 1 sleep(200) WEnd EndFunc Func mbox() msgbox(0,"","Im a message box!") EndFunc Thanks for taking a look Edited January 8, 2009 by cmattb Link to comment Share on other sites More sharing options...
BrettF Posted January 7, 2009 Share Posted January 7, 2009 Hi, The second while loop is not needed. Maybe try this: #include <GUIConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Opt("TrayIconDebug", 1) Global $gui1 = GUICreate("GUI numer one", 200, 200) Global $button1 = GUICtrlCreateButton("Go GUI #2!", 50, 50) GUICtrlSetOnEvent($button1, "gui2") GUISetState(@SW_SHOW) While 1 Sleep(200) WEnd Func gui2() Global $gui2 = GUICreate("GUI numer two", 150, 150) Global $button2 = GUICtrlCreateButton("msg box", 20, 50) GUICtrlSetOnEvent($button2, "mbox") GUISetState(@SW_SHOW) GUISetState (@SW_DISABLE, $gui1) EndFunc ;==>gui2 Func mbox() MsgBox(0, "", "Im a message box!") EndFunc ;==>mbox Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
cmattb Posted January 7, 2009 Author Share Posted January 7, 2009 That fixed that. That was just an example script, and I was hoping that would answer enough for me to get the actual script working, but no go for that. So heres a more accurate example script. The problem is that the $ailoc GUI works great the first time, but the second time through the loop, the OK button no longer calls the second function. I've tried everything I can think of, but no success so far. If theres a better way to do something like this than using two functions, Im open to that idea as well. expandcollapse popup#include <GUIConstants.au3> #include <ButtonConstants.au3> Opt("GUIOnEventMode", 1) Opt("TrayIconDebug",1) Global $autoinstallgui = GUICreate("Parent", 200, 800) global $label=GUICtrlCreateEdit (""&@CRLF, 0,0,200,700) GUISetState(@SW_SHOW, $autoinstallgui) Global $aiinfo[5] $aiinfo[1] = "" $aiinfo[2] = "" $aiinfo[3] = "" Global $num = 1 driverinstall() while 1 sleep(200) Wend Func driverinstall() Do If $aiinfo[$num] = "" Then Global $locerror = guicreate("File Location Error",250,100) GUISwitch ($locerror) Global $ailoc = GUICtrlCreateInput("", 10, 5, 300, 20) $btn = GUICtrlCreateButton("&Ok", 40, 75, 60, 20, $BS_DEFPUSHBUTTON) GUICtrlSetOnEvent($btn, "updateloc") GUISetState (@SW_SHOW, $locerror) While 1 Sleep(200) WEnd Endif GUICtrlSetData($label, $num& " - "&$aiinfo[$num]&@CRLF, 1) $num = $num + 1 Until $num = 4 EndFunc Func updateloc() $aiinfo[$num] = GuiCtrlRead($ailoc) GUISwitch ($autoinstallgui) GUIDelete($locerror) driverinstall() EndFunc Thanks again Link to comment Share on other sites More sharing options...
sandin Posted January 7, 2009 Share Posted January 7, 2009 why using multiple do/while(s)? try making all controls into single while 1 #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 400, 300) $Button1 = GUICtrlCreateButton("Button1", 50, 80, 200, 50) GUISetState(@SW_SHOW) $Form2 = GUICreate("Form2", 200, 100) $Button2 = GUICtrlCreateButton("Button2", 10, 10, 100, 30) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE If WinActive($Form2) Then GUIDelete($Form2) if (NOT WinExists($Form1)) then Exit ElseIf WinActive($Form1) Then GUIDelete($Form1) if (NOT WinExists($Form2)) then Exit EndIf case $Button1 MsgBox(0, "Form1 msg", "button1 on form1 pressed") case $Button2 MsgBox(0, "Form2 msg", "button2 on form2 pressed") EndSwitch WEnd Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll Link to comment Share on other sites More sharing options...
cmattb Posted January 7, 2009 Author Share Posted January 7, 2009 (edited) The problem is the rest of the script is using Opt("GUIOnEventMode", 1) so I cant use case's. What I need is a parent window that cycles through an array, outputting the variables to Edit. If the variable is blank, then another window pops up, asking for the variable. The only way I could think of of doing this is with a child GUI. The child GUI works great the first time, but if a second variable is missing from the array the OK button no longer calls the second function. I revised the code a bit so that the child GUI never gets deleted, only hidden, but the OK button still doesnt work the second time around. expandcollapse popup#include <GUIConstants.au3> #include <ButtonConstants.au3> Opt("GUIOnEventMode", 1) Opt("TrayIconDebug",1) Global $autoinstallgui = GUICreate("Parent", 200, 800) global $label=GUICtrlCreateEdit (""&@CRLF, 0,0,200,700) GUISetState(@SW_SHOW, $autoinstallgui) Global $locerror = guicreate("File Location Error",250,100) GUISwitch ($locerror) Global $ailoc = GUICtrlCreateInput("", 10, 5, 300, 20) $btn = GUICtrlCreateButton("&Ok", 40, 75, 60, 20, $BS_DEFPUSHBUTTON) GUICtrlSetOnEvent($btn, "updateloc") GUISetState (@SW_HIDE, $locerror) GUISwitch ($autoinstallgui) Global $aiinfo[5] Global $num = 1 driverinstall() while 1 sleep(200) Wend Func driverinstall() Do If $aiinfo[$num] = "" Then GUISwitch ($locerror) GUISetState (@SW_SHOW, $locerror) While 1 sleep(200) WEnd Endif GUICtrlSetData($label, $num& " - "&$aiinfo[$num]&@CRLF, 1) $num = $num + 1 Until $num = 4 EndFunc Func updateloc() $aiinfo[$num] = GuiCtrlRead($ailoc) GUISwitch ($autoinstallgui) driverinstall() EndFunc Edited January 7, 2009 by cmattb Link to comment Share on other sites More sharing options...
cmattb Posted January 8, 2009 Author Share Posted January 8, 2009 I don't know whats up with the child GUI, but I just found the InputBox function. Its exactly what I need. If anyones interest, working code example is below: #include <GUIConstants.au3> #include <ButtonConstants.au3> Opt("GUIOnEventMode", 1) Opt("TrayIconDebug",1) Global $autoinstallgui = GUICreate("Parent", 200, 800) global $label=GUICtrlCreateEdit (""&@CRLF, 0,0,200,700) GUISetState(@SW_SHOW, $autoinstallgui) Global $aiinfo[5] Global $num = 1 driverinstall() while 1 sleep(200) Wend Func driverinstall() Do If $aiinfo[$num] = "" Then $aiinfo[$num] = InputBox("Missing File Location", "File Location:", "", "") GUICtrlSetData($label, $num& " - "&$aiinfo[$num]&@CRLF, 1) $num = $num + 1 Until $num = 4 EndFunc 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