Sign in to follow this  
Followers 0
LordRaven

Setting ComboBox values

8 posts in this topic

#1 ·  Posted (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 by LordRaven

Share this post


Link to post
Share on other sites



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 read

Read 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. :unsure:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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. :unsure:

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

@Melba23

Sorry 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

Share this post


Link to post
Share on other sites

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
WEnd

As 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
EndSwitch

Select: 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
EndSwitch

They are both useful, but have different applicability depending on how you need your Case statements to be constructed. ;)

All clear? :unsure:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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? :unsure:

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")
            EndSelect

So, Thanks very much for all your help Melba23

Have a nice day, and a good night friend!

Share this post


Link to post
Share on other sites

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. :unsure:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0