nikol4s Posted February 22, 2012 Share Posted February 22, 2012 (edited) Hey guys, I have a really dumb question, I am just trying to learn AutoIT so please don't slam your heads on your desks, lol. Okay. Basically, I've created a ComboBox and a Button on my GUI in Koda. #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Test", 148, 97, 192, 114) GUICtrlCreateCombo("", 0, 16, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "TestItem1|TestItem2") $Button1 = GUICtrlCreateButton("Button1", 32, 48, 83, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Very basic, I am going to add more after I figure it out more. What I am trying to do is when the Button is pressed, I want it to check the ComboBox and do something differently depending on what item is in the ComboBox at the time. I tried some stuff such as While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 If $Form1 = "TestItem1" Then ControlSetText ( "MH]", "","[CLASS:WindowsForms10.EDIT.app.0.2bf8098_r13_ad1; INSTANCE:2]", "test" ) EndIf EndSwitch WEnd Let me add that the ControlSetText does work when the button is pressed if I do not include an If statement, so I know I am doing something wrong. Please help me . Basically... when a button is pressed, if a particular item is selected in the combobox I want it to perform a particular action (ControlSetText). Signed, AutoIT Noob. Edited February 22, 2012 by nikol4s Link to comment Share on other sites More sharing options...
hannes08 Posted February 22, 2012 Share Posted February 22, 2012 Hello nikol4s, you can use GuiCtrlRead to obtain the current value of the combobox. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
Dana Posted February 22, 2012 Share Posted February 22, 2012 $Form1 is the handle of the overall GUI, not what contains the selected item in the combo box. You should use $combo1 = GUICtrlCreateCombo("", 0, 16, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData($combo1, "TestItem1|TestItem2") Then Case $Button1 If GUICtrlRead($combo1) = "TestItem1" Then ControlSetText ( "MH]", "","[CLASS:WindowsForms10.EDIT.app.0.2bf8098_r13_ad1; INSTANCE:2]", "test" ) EndIf Link to comment Share on other sites More sharing options...
Aktonius Posted February 22, 2012 Share Posted February 22, 2012 (edited) For several items in combobox you better learn to use switch, it looks much better and is better organized While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Switch GUICtrlRead($combo1) Case "TestItem1" ControlSetText("MH]", "", "[CLASS:WindowsForms10.EDIT.app.0.2bf8098_r13_ad1; INSTANCE:2]", "test") Case "TestItem2" ControlSetText("MH]", "", "[CLASS:WindowsForms10.EDIT.app.0.2bf8098_r13_ad1; INSTANCE:2]", "test2") Case "TestItem3" ControlSetText("MH]", "", "[CLASS:WindowsForms10.EDIT.app.0.2bf8098_r13_ad1; INSTANCE:2]", "test2") EndSwitch EndSwitch WEnd Edited February 22, 2012 by Aktonius 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