Sign in to follow this  
Followers 0
Josbe

Gui - Combo

7 posts in this topic

How I can get a number of item from a combo?

For example: In my list I have "red|green|blue", if I select "blue", wanted also to know that number located in the list. In this case: 2. If "red" is "0", "green" is 1. I have tested using GUIRecvMsg with some variables, but not achievement to obtain this value. (maybe I dont choosing the correct var) :D

There is some way? :huh2:

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I use :

$select = GUIRead( $combo) - $combo is set up by $combo = GUISetControl("combo", ...)

$select will be either red, blue or green in your example.

$occur = ControlCommand($title, "", "ComboBox1", "FindString", $select) - where "ComboBox1" is the control identiy for the combobox returned by window spy

$occur = 0 for the first item (red) in the combobox, 1 for the second item (blue)and so on

Edited by alawoona

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can store what the list is somewhere and StringSplit it and then iterate each element...

Pseudo code:

$data = "red|green|blue"
$list = GuiSetControl()
GuiSetControlData($list, $data)

$res = GuiRead($list)
$index = GetIndex($res, $data)

; $s = string, $d = data
; Returns the index or 0 (Check @error for failure!)
Func GetIndex($s, $d)
    Local $a = StringSplit($d, "|")
    Local $i
    For $i = 1 To $a[0]
        If $a[$i] = $s Then Return $i
    Next
    SetError(1)
    Return 0
EndFunc

Note: This assumes a indexing starts at 1. If you would rather see indexing start at 0, then use Return $i - 1 (Indexing starting at 1, though, will leave 0 as a safe return value to check...).

Edited by Valik

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I use a "trick" in AutoBuilder (similar to Valik's method above).

I used fixed-width entries, but remove the whitespace before using them in the combo box data.

Here's an edited example:

Global $REC_WIDTH = 9;each record is 9-characters long
Global $RECORDS = "avi   |button  |checkbox|combo   |date  |edit  |"

Global $CONTROL_LIST = StringStripWS($RECORDS,8);strip all spaces
; $Control_list is in the correct format for setting the data of a combo box

; Lookup returns the index of the item....  First index is zero.

Func Lookup($CTRL) ;parameter is a the name of the combo box item
    Return Int(StringInStr($RECORDS, $CTRL) / $REC_WIDTH)
EndFunc
Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Josbe, this should help:

Global $CB_GETCURSEL = 0x147;
$index = GuiSendMsg($comboRef, $CB_GETCURSEL, 0, 0)
MsgBox(4096,"Value", $index)

Look at

http://msdn.microsoft.com/library/default....b_getcursel.asp

and similar pages to find right message and parameters

I use the program ApiViewer 2002 to find the hexadecimal values of constants.

If I get time, I wil compile a list of messages that you can send to controls.....

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

Josbe, this should help:

Global $CB_GETCURSEL = 0x147;
$index = GuiSendMsg($comboRef, $CB_GETCURSEL, 0, 0)
MsgBox(4096,"Value", $index)

Look at

http://msdn.microsoft.com/library/default....b_getcursel.asp

and similar pages to find right message and parameters

I use the program ApiViewer 2002 to find the hexadecimal values of constants.

If I get time, I wil compile a list of messages that you can send to controls.....

::cough:: winuser.h ::cough:: Almost all of the styles and messages are defined in that file. You could probably spend 20-30 minutes writing some kind of parser (In AutoIt, of course) that goes through and extracts the WM_*, CBS_*, LBS_*, ES_*, stuff and writes it out in AutoIt format.

Share this post


Link to post
Share on other sites

Josbe, this should help:

Global $CB_GETCURSEL = 0x147;
$index = GuiSendMsg($comboRef, $CB_GETCURSEL, 0, 0)
MsgBox(4096,"Value", $index)

Look at

http://msdn.microsoft.com/library/default....b_getcursel.asp

and similar pages to find right message and parameters

I use the program ApiViewer 2002 to find the hexadecimal values of constants.

If I get time, I wil compile a list of messages that you can send to controls.....

Thanks CyberSlug, exactly what I wanted! :):D

...and thanks alawoona and Valik for ideas. :huh2:

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