John117 Posted January 16, 2012 Share Posted January 16, 2012 I have a list that fills a combo box. Instead of "GUICtrlRead($SomeRandomBox)" returning the value of the data in the box, I would like it to return the position in the list. In that example, the below code would return '2' not "second". #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $msg GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered GUICtrlCreateCombo("", 10, 10) ; create first item GUICtrlSetData(-1, "First|Second|Third", "Second") ; add other item snd set a new default GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>Example I am trying to avoid: If GUICtrlRead($SomeRandomBox) = "First" Then $Value = 1 If GUICtrlRead($SomeRandomBox) = "Second" Then $Value = 2 I am guessing there is an easier way, since the list will grow. Link to comment Share on other sites More sharing options...
Malkey Posted January 17, 2012 Share Posted January 17, 2012 Here is one method of returning the position of an item in a combo box list. ;#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $msg, $idCombo, $idBut, $index, $sList = "First|Second|Third|F" GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered $idCombo = GUICtrlCreateCombo("", 10, 10) ; create first item GUICtrlSetData(-1, $sList, "Second") ; add other item snd set a new default $idBut = GUICtrlCreateButton("Read", 220, 10, 50, 22) GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Switch $msg Case -3 ;$GUI_EVENT_CLOSE ExitLoop Case $idBut ; Count the number of "|"s before the selected item in the combo box list, plus one. StringReplace(StringLeft("|" & $sList & "|", StringInStr("|" & $sList & "|", "|" & GUICtrlRead($idCombo) & "|")), "|", "|") $index = @extended MsgBox(0, "Result", "Position in list = " & $index, 3) EndSwitch WEnd EndFunc ;==>Example Link to comment Share on other sites More sharing options...
czardas Posted January 17, 2012 Share Posted January 17, 2012 _GUICtrlComboBox_FindString() and _GUICtrlComboBox_FindStringExact() are also useful functions for this. Look in the help file. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
lark Posted January 17, 2012 Share Posted January 17, 2012 (edited) Look in the help file for:_GUICtrlComboBox_FindString Edit: looks like some people beat me to it, a minute early Edited January 17, 2012 by mischieftoo Link to comment Share on other sites More sharing options...
John117 Posted January 17, 2012 Author Share Posted January 17, 2012 Thank you very much! Will get to it! 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