IvanCodin Posted September 20, 2009 Posted September 20, 2009 (edited) <Edit entire post for clarity and better example>I have a script I am currently using and want to modify it. I have a GUI with buttons that sends me to the next GUI based on the button pressed. I want to convert it to a Combo Box and can't see how to make it work. Below is an example of the current config I made and an example of how I would like it be modified:expandcollapse popup#include <GUIConstantsEX.au3> #include <Misc.au3> #include <Process.au3> #Include <GuiEdit.au3> Opt('GUIOnEventMode', True) ;Opt('MustDeclareVars', 1) Global $Width = ('499') Global $Height = ('447') HotKeySet("^x", "_Bye") ; I am currently using buttons to access my other menus $hGUI5 = GUICreate("Tools", $Width, $Height, 270, 98) GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $hGUI5) $Context_Menu = GUICtrlCreateContextMenu() $Item_1 = GUICtrlCreateMenuItem("About", $Context_Menu) GUICtrlSetOnEvent ($Item_1,"_About") $Item_2 = GUICtrlCreateMenuItem("Exit", $Context_Menu) GUICtrlSetOnEvent ($Item_2,"_Exit") GUICtrlCreateLabel("<==== Config Info ===>", 115, 10) $cCommand5_1 = GUICtrlCreateEdit("", 20, 40, 365, 397) GUICtrlSetFont(-1, Default, Default, 1, "Courier New") $Button5_20 = GUICtrlCreateButton("Config G2", 392, 77, 89, 23, 0) GUICtrlSetOnEvent($Button5_20,"SwitchGUI") $Button5_21 = GUICtrlCreateButton("Config G3", 392, 108, 89, 23, 0) GUICtrlSetOnEvent($Button5_21, "SwitchGUI") $Button5_22 = GUICtrlCreateButton("Config G4", 392, 139, 89, 23, 0) GUICtrlSetOnEvent($Button5_22, "SwitchGUI") ; I would like to switch to a combo box that does the same as the 3 buttons(Config G2, Config G3, Config G4) I already in the menu. How do I do that based on the ComboBox selection? ;Something like: ; GUICtrlCreateCombo("", 392, 10) ; GUICtrlSetData(-1, "G2|G3|G4|G5|G7", "G4") ; GUISetState() ; => Begin G2 $G2Form = GUICreate("Tools - G Gateway", $Width, $Height, 270, 98) GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $G2Form) $Context_Menu = GUICtrlCreateContextMenu() $Item_1 = GUICtrlCreateMenuItem("About", $Context_Menu) GUICtrlSetOnEvent ($Item_1,"_About") $Item_2 = GUICtrlCreateMenuItem("Exit", $Context_Menu) GUICtrlSetOnEvent ($Item_2,"_Exit") GUICtrlCreateLabel("<== G2 Gateway ==>", 115, 10) GUICtrlCreateGroup ("",20, 30, 365, 397) GUICtrlCreateLabel ("IP Address => ",30,46) $G2IP = GUICtrlCreateInput ("",115,46,150,20) GUICtrlSetLimit ($G2IP, '23','23') GUICtrlCreateLabel ("Mask => ",30,77) $G2IP_Mask = GUICtrlCreateInput ("",115,77,150,20) GUICtrlSetLimit ($G2IP_mask, '23','23') GUICtrlCreateLabel ("Gateway => ",30,108) $G2IP_GW = GUICtrlCreateInput ("",115,108,150,20) GUICtrlSetLimit ($G2IP_GW, '23','23') $G2But2 = GUICtrlCreateButton("Make My Config", 392, 46, 89, 23, 0) $GW_Type = "G2" GUICtrlSetOnEvent($G2But2,"Config_G2") $G2But10 = GUICtrlCreateButton("Return", 392, 418, 89, 23, 0) GUICtrlSetOnEvent($G2But10, "SwitchGUI") ; => End G2 form ; => Begin G3 $G3Form = GUICreate("Tools - G3 Gateway", $Width, $Height, 270, 98) GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $G3Form) $Context_Menu = GUICtrlCreateContextMenu() $Item_1 = GUICtrlCreateMenuItem("About", $Context_Menu) GUICtrlSetOnEvent ($Item_1,"_About") $Item_2 = GUICtrlCreateMenuItem("Exit", $Context_Menu) GUICtrlSetOnEvent ($Item_2,"_Exit") GUICtrlCreateLabel("<== G4 Gateway ==>", 115, 10) GUICtrlCreateGroup ("",20, 30, 365, 397) GUICtrlCreateLabel ("IP Address => ",30,46) $G3IP = GUICtrlCreateInput ("",115,46,150,20) GUICtrlSetLimit ($G3IP, '23','23') GUICtrlCreateLabel ("Mask => ",30,77) $G3IP_Mask = GUICtrlCreateInput ("",115,77,150,20) GUICtrlSetLimit ($G3IP_mask, '23','23') GUICtrlCreateLabel ("Gateway => ",30,108) $G3IP_GW = GUICtrlCreateInput ("",115,108,150,20) GUICtrlSetLimit ($G3IP_GW, '23','23') $G3But2 = GUICtrlCreateButton("Make My Config", 392, 46, 89, 23, 0) $GW_Type = "G3" GUICtrlSetOnEvent($G3But2,"Config_G3") $G3But10 = GUICtrlCreateButton("Return", 392, 418, 89, 23, 0) GUICtrlSetOnEvent($G3But10, "SwitchGUI") ; => End G3 form ; => Begin G4 $G4Form = GUICreate("Tools - G4 Gateway", $Width, $Height, 270, 98) GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $G4Form) GUICtrlCreateLabel("<== G4 Gateway ==>", 115, 10) GUICtrlCreateGroup ("",20, 30, 365, 397) GUICtrlCreateLabel ("IP Address => ",30,46) $G4IP = GUICtrlCreateInput ("",115,46,150,20) GUICtrlSetLimit ($G4IP, '23','23') GUICtrlCreateLabel ("Mask => ",30,77) $G4IP_Mask = GUICtrlCreateInput ("",115,77,150,20) GUICtrlSetLimit ($G4IP_mask, '23','23') GUICtrlCreateLabel ("Gateway => ",30,108) $G4IP_GW = GUICtrlCreateInput ("",115,108,150,20) GUICtrlSetLimit ($G4IP_GW, '23','23') $G4But2 = GUICtrlCreateButton("Make My Config", 392, 46, 89, 23, 0) $GW_Type = "G4" GUICtrlSetOnEvent($G4But2,"Config_G4") $G4But10 = GUICtrlCreateButton("Return", 392, 418, 89, 23, 0) GUICtrlSetOnEvent($G4But10, "SwitchGUI") ; => End G4 form GUISetState(@SW_SHOW, $hGUI5) While 1 Sleep(20) ; Idle around WEnd Func SwitchGUI() Switch @GUI_CtrlId Case $Button5_20 ; G2 to gateways $Pos = WinGetPos($hGUI5) WinMove($G2Form, "", $Pos[0], $Pos[1]) GUISetState(@SW_Hide, $hGUI5) GUISetState(@SW_SHOW, $G2Form) Case $Button5_21 ; G3 to gateways $Pos = WinGetPos($hGUI5) WinMove($G3Form, "", $Pos[0], $Pos[1]) GUISetState(@SW_Hide, $hGUI5) GUISetState(@SW_SHOW, $G3Form) Case $Button5_22 ; G4 to gateways $Pos = WinGetPos($hGUI5) WinMove($G4Form, "", $Pos[0], $Pos[1]) GUISetState(@SW_Hide, $hGUI5) GUISetState(@SW_SHOW, $G4Form) Case $G2But10 ; Return Gateweay $Pos = WinGetPos($G2Form) WinMove($hGUI5, "", $Pos[0], $Pos[1]) GUISetState(@SW_Hide, $G2Form) GUISetState(@SW_SHOW, $hGUI5) Case $G3But10 ; Return Gateway $Pos = WinGetPos($G3Form) WinMove($hGUI5, "", $Pos[0], $Pos[1]) GUISetState(@SW_Hide, $G3Form) GUISetState(@SW_SHOW, $hGUI5) Case $G4But10 ; Return Gateway $Pos = WinGetPos($G4Form) WinMove($hGUI5, "", $Pos[0], $Pos[1]) GUISetState(@SW_Hide, $G4Form) GUISetState(@SW_SHOW, $hGUI5) Case Else ; start up and default gui shown GUISetState(@SW_Hide, $G2Form) GUISetState(@SW_Hide, $G3Form) GUISetState(@SW_Hide, $G4Form) GUISetState(@SW_SHOW, $hGUI5) EndSwitch EndFunc ;==>SwitchGUI GUISetState(@SW_SHOW, $hGUI5) Func Config_G2() $GW_Type = "G2" SplashTextOn("Info", "Gateway style selected is G2", 380, 55) Sleep(3000) SplashOff() ; _CreateGWDoc() EndFunc Func Config_G3() $GW_Type = "G3" SplashTextOn("Info", "Gateway style selected is G3", 380, 55) Sleep(3000) SplashOff() ; _CreateGWDoc() EndFunc Func Config_G4() $GW_Type = "G4" SplashTextOn("Info", "Gateway style selected is G4", 380, 55) Sleep(3000) SplashOff() ; _CreateGWDoc() EndFunc Func _Bye() ;SoundPlay(@WindowsDir & "\media\tada.wav",1) $return_value = MsgBox(292, "Close Application", "Do you want to close CTools?", 10) Switch $return_value case 1 ;OK ---> Flags: 0, 1 ;MsgBox(0, "Return Value", "OK") case 2 ;cancel ---> Flags: 1, 3, 5, 6 ;MsgBox(0, "Return Value", "Cancel") case 3 ;abort ---> Flags: 2 ;MsgBox(0, "Return Value", "Abort") case 4 ;retry ---> Flags: 2, 5 ;MsgBox(0, "Return Value", "Retry") case 5 ;Ignore ---> Flags: 2 ;MsgBox(0, "Return Value", "Ignore") case 6 ;Yes ---> Flags: 3, 4 ;MsgBox(0, "Return Value", "Yes") _Exit() case 7 ;No ---> Flags: 3, 4 ;MsgBox(0, "Return Value", "No") Return case 10 ;Try Again ---> Flags: 6 ;MsgBox(0, "Return Value", "Try again") case 11 ;Continue ---> Flags: 6 ;MsgBox(0, "Return Value", "Continue") EndSwitch ;MsgBox(1, "Bye", "Exiting program", 4) ;_Exit() EndFunc ;==>_Bye Func _About() MsgBox(0, "About", "My Tool Box", 4) EndFunc ;==>_About Func _Exit() ;MsgBox(1, "Bye", "Exiting program", 4) ;_Exit() GUIDelete($hGUI5) GUIDelete($G2Form) GUIDelete($G3Form) GUIDelete($G4Form) Exit EndFunc ;==>_ExitWhen I set MustDeclareVars to 1 I get errors in the script. I thought, obviously in error, GUICtrlSetOnEvent set the variable to the button selection in the example below:$Button5_20 = GUICtrlCreateButton("Config G2", 392, 77, 89, 23, 0)GUICtrlSetOnEvent($Button5_20,"SwitchGUI")How do I set the variable based on the button press? I would like to use the MustDeclairVars but will needs to correct my script to use them correctly.CC Edited September 21, 2009 by IvanCodin
Bert Posted September 21, 2009 Posted September 21, 2009 Instead of posting your entire program, just post a small example of what you are having the trouble with. When folks see that large script, they tend not to wish to fix it. The Vollatran project My blog: http://www.vollysinterestingshit.com/
IvanCodin Posted September 21, 2009 Author Posted September 21, 2009 My actual program is 1900 lines. I wrote and posted the code as an example of what I am trying to do. Instead of buttons on the GUI I would like to use a Combo Box or perhaps Radio Buttons.I am using OnEvent mode in my script and a majority of the examples I find in the Forum show Message Mode. I spent quite a bit of time yesterday looking in the Forum for an answer but can't find anything close. If some could point me in the right direction I would greatly appreciate it. Me
PsaltyDS Posted September 21, 2009 Posted September 21, 2009 My actual program is 1900 lines. I wrote and posted the code as an example of what I am trying to do. Instead of buttons on the GUI I would like to use a Combo Box or perhaps Radio Buttons.I am using OnEvent mode in my script and a majority of the examples I find in the Forum show Message Mode. I spent quite a bit of time yesterday looking in the Forum for an answer but can't find anything close. If some could point me in the right direction I would greatly appreciate it. Me It's still way too long to simply illustrate the single function this topic is about. Here's a much simpler demo of a ComboBox in event mode: expandcollapse popup#include <GuiConstantsEx.au3> Opt("GuiOnEventMode", 1) Global $hGUI, $ctrlCombo, $ctrlButton1 $hGUI = GUICreate("Test", 300, 300) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") $ctrlCombo = GUICtrlCreateCombo("Not Selected", 20, 20, 260) GUICtrlSetOnEvent(-1, "_ComboEvent") For $n = 1 To 10 GUICtrlSetData($ctrlCombo, "Option Number " & $n) Next $ctrlButton1 = GUICtrlCreateButton("SELECT", 100, 250, 100, 30) GUICtrlSetOnEvent(-1, "_ButtonEvent") GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() While 1 Sleep(10) WEnd Func _ComboEvent() If GUICtrlRead($ctrlCombo) = "Not Selected" Then GUICtrlSetState($ctrlButton1, $GUI_DISABLE) Else GUICtrlSetState($ctrlButton1, $GUI_ENABLE) EndIf EndFunc ;==>_ComboEvent Func _ButtonEvent() MsgBox(64, "_ButtonEvent()", "Selected: " & GUICtrlRead($ctrlCombo), 5) EndFunc ;==>_ButtonEvent Func _Quit() Exit EndFunc ;==>_Quit Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
IvanCodin Posted September 21, 2009 Author Posted September 21, 2009 Sorry my original post got no responses so I felt everyone thought I was to lazy to write the code. So I wrote the entire fricking thing to show everyone what I was tring to do. As always thanks for your assist. Me
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