mattschinkel Posted January 3, 2010 Share Posted January 3, 2010 How do I get strings from a list box? I am able to add strings with this: ControlCommand ("MDSI", "", 1, "AddString", "string") I am not able to use controlgettext. Thanks, Matt. Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 4, 2010 Share Posted January 4, 2010 How do I get strings from a list box? I am able to add strings with this: ControlCommand ("MDSI", "", 1, "AddString", "string") I am not able to use controlgettext. Thanks, Matt. To use ControlCommand(), you would select each item in a loop with "SetCurrentSelection", and get its text with "GetCurrentSelection". The loop exits when selection fails: #include <GuiConstantsEx.au3> Global $hGUI, $ctrlButton, $ctrlLB $hGUI = GUICreate("MDSI", 300, 300) $ctrlLB = GUICtrlCreateList("Item 0", 20, 20, 260, 210) For $n = 1 To 19 GUICtrlSetData($ctrlLB, "Item " & $n) Next $ctrlButton = GUICtrlCreateButton("READ", 100, 250, 100, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $ctrlButton _ReadItems() EndSwitch WEnd Func _ReadItems() Local $n = 0, $sTxt = "", $sMsg = "" While 1 ControlCommand("MDSI", "", $ctrlLB, "SetCurrentSelection", $n) If @error Then ExitLoop ; Done $sTxt = ControlCommand("MDSI", "", $ctrlLB, "GetCurrentSelection", "") $sMsg &= $n & ": " & $sTxt & @CRLF $n += 1 WEnd MsgBox(64, "Result", $sMsg) EndFunc ;==>_ReadItems There are more advanced UDF functions that can get the count and read the items without selecting each one, like _GUICtrlListBox_GetCount() and _GUICtrlListBox_GetText(): #include <GuiListBox.au3> ; Rest of script body is the same... Func _ReadItems() Local $hLB = ControlGetHandle("MDSI", "", $ctrlLB) Local $iCnt = _GUICtrlListBox_GetCount($hLB) Local $sMsg = "" For $n = 0 To $iCnt - 1 $sMsg &= $n & ": " & _GUICtrlListBox_GetText($hLB, $n) & @CRLF Next MsgBox(64, "Result", $sMsg) EndFunc ;==>_ReadItems Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
mattschinkel Posted January 5, 2010 Author Share Posted January 5, 2010 The 2nd example works great thanks. Maybe this should be added to the Autoit releases since there is currently no command for retrieving text from list boxes in external programs. Matt. 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