LordRaven Posted May 22, 2011 Posted May 22, 2011 (edited) Hey guys, hi again. Im here with a new doubt. Now I am trying to work with combobox function. I've read help file, and did search a lot over forum about it, but I couldnt find what I really needed. I need to know how to put ComboBox values, so I can click on Set button and one defined var, will get different values, depending on the content chosen on combobox, the reason of this is code saving, so i dont need to create like 3 functions in a gui for example to call 3 distinct functions. Here is what I need, I need to know how to put fix values in a ComboBox for starting, like: ComboBox Values: Test 1 Test 2 Test 3 Then I got a Button called Set. When I click it, it sets a determined value to the $opt var, for example, if rolled combo to Test 1, it sets my $opt var to 'x', if i roll to Test 2, it sets my $opt var to 'y', and if i roll my combo to Test 3 and click set, it should set my $opt var to the value z. Follows the GUI Code: #include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form2", 228, 62, 303, 219) $Combo1 = GUICtrlCreateCombo("Combo1", 16, 16, 145, 25) $Button1 = GUICtrlCreateButton("Set", 168, 16, 43, 17, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Sorry guys if my questions sound noobish, is that I still begginner in AutoIt coding. Edited May 22, 2011 by LordRaven
Moderators Melba23 Posted May 22, 2011 Moderators Posted May 22, 2011 LordRaven,Use GUICtrlSetData initially to put the "Test 1/2/3" values in the combo.Then within your GUIGetMsg Switch structure you need a Case for your Set button - in the code for that case you will need to:- Use GUICtrlRead to get the value selected in the combo- Use a further Switch structure to set the $opt variable depending on the value readRead about those commands in the Help file (you did say you were going to read it more carefully ) and see what you come up with. You know where we are if you run into difficulties. 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: Reveal hidden contents 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
LordRaven Posted May 22, 2011 Author Posted May 22, 2011 Sorry friend, I wish my logic was better, but sometimes I stuck even reading help file.I follow everything you said and I'm getting error in expression.Follows the code:#include <GUIConstants.au3> Global $readed #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form2", 228, 62, 303, 219) $Combo1 = GUICtrlCreateCombo("", 16, 16, 145, 25) GUICtrlSetData(-1, "Test 1|Test 2|Test 3") $Button1 = GUICtrlCreateButton("Set", 168, 16, 43, 17, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $readed = GUICtrlRead($Combo1) Switch Case $readed == "Test 1" MsgBox(0,"Value","The Value Returned was X") Case $readed == "Test 2" MsgBox(0,"Value","The Value Returned was Y") Case $readed == "Test 3" MsgBox(0,"Value","The Value Returned was Z") EndSwitch EndSwitch WEnd
Moderators Melba23 Posted May 22, 2011 Moderators Posted May 22, 2011 LordRaven,Compare the syntax of the 2 Switch structures in your code:; This one works Switch $nMsg Case $GUI_EVENT_CLOSE ; This one does not Switch Case $readed == "Test 1"Can you see the difference? Try making the second look more like the first. When you have the time, you might like to look at Switch and Select in the Help file - they are close relatives but their syntax is quite different and you are confusing the two at the moment. 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: Reveal hidden contents 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
LordRaven Posted May 22, 2011 Author Posted May 22, 2011 @Melba23Sorry for the dumb syntax error, sometimes I forgot stuffs...Oh about Select and Switch, I've been thinking, those 2 looks like they have the exacly same function to me.Am I wrong? They different in any case? Could you point me which they got different than other? Thanks once again Melba23, you're a life savior.Oh almost forgot, the code.Here is it, if someone need anytime:#include <GUIConstants.au3> Global $readed #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form2", 228, 62, 303, 219) $Combo1 = GUICtrlCreateCombo("", 16, 16, 145, 25) GUICtrlSetData(-1, "Test 1|Test 2|Test 3") $Button1 = GUICtrlCreateButton("Set", 168, 16, 43, 17, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $readed = GUICtrlRead($Combo1) Switch $readed Case $readed == "Test 1" MsgBox(0,"Value","The Value Returned was X") Case $readed == "Test 2" MsgBox(0,"Value","The Value Returned was Y") Case $readed == "Test 3" MsgBox(0,"Value","The Value Returned was Z") EndSwitch EndSwitch WEnd
Moderators Melba23 Posted May 22, 2011 Moderators Posted May 22, 2011 LordRaven,It should read like this - your version is not syntactically correct and I am surprised it works: While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $readed = GUICtrlRead($Combo1) Switch $readed Case "Test 1" ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< MsgBox(0,"Value","The Value Returned was X") Case "Test 2" ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< MsgBox(0,"Value","The Value Returned was Y") Case "Test 3" ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< MsgBox(0,"Value","The Value Returned was Z") EndSwitch EndSwitch WEndAs to the difference between Switch and Select:Switch: You choose the single variable at the beginning and then set the Case parameters to specific values or ranges of that variable like this:Switch $vVariable Case 1 ; Code Case 2, 3 ; Easy to have multiple values ; Code Case 4 To 9 ; Easy to use ranges EndSwitchSelect: You can have different variables in each Case like this:Select Case $vVar_One = 23 ; Code Case $vVar_One < 123 ; You only get here if $vVar_One <> 23 ; Code Case $vVar_Two = "Fred" ; And here we have a different variable altogether ; Code EndSwitchThey are both useful, but have different applicability depending on how you need your Case statements to be constructed. 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: Reveal hidden contents 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
LordRaven Posted May 22, 2011 Author Posted May 22, 2011 Now I got it.Relate to my another Syntax error, on C programming which is the one im working with in my university, the switch works that way. Thats why I put that way the code.The right way for me to use should be making using a select then isnt?(for the syntatically incorrect way i was using) If was using a select wouldnt be wrong isnt? Like this:Select Case $readed = "Test 1" MsgBox(0,"Value","The Value Returned was X") Case $readed = "Test 2" MsgBox(0,"Value","The Value Returned was Y") Case $readed = "Test 3" MsgBox(0,"Value","The Value Returned was Z") EndSelectSo, Thanks very much for all your help Melba23Have a nice day, and a good night friend!
Moderators Melba23 Posted May 22, 2011 Moderators Posted May 22, 2011 LordRaven,You are correct, your syntax was perfect for Select - which is why I was so surprised it also worked for Switch! One small point: Using == in AutoIt is only required when you want a case-sensitive comparison between strings - in all other cases it is best to use a single = as you did in the snippet above. Glad I could help. 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: Reveal hidden contents 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
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