Home > Language Reference > Windows Management Functions > ListItem$

ListItem$

The ListItem$ function returns the text of the nth item name in a listbox or combobox.

Usage

Used to retrieve the text of an item in a list. Only standard Windows list/combo work with ListItem$. With a non-standard list/combo, you can use Clipboard :
SendKeys("<Ctrl c">)
to copy the text to Clipboard, and GetClipboard$ function to retrieve the content of Clipboard.  

Syntax

var$=ListItem$(<window_name>, <index>)

Parameters

<window_name>, string, window name of the listbox/combobox.

<index>, integer. First item starts at <index> 0, for example to retrieve the 4th item, use 3 for <index>.

Return value

var$, string, text of the item. If the item does not exist, no error is reported and the return value is empty (an empty string is "").

See also

SelectedItem$

Examples

a$=ListItem$("NOTEPAD.EXE|ComboBox|Font|5",3 )
msgbox(a$)


'The script below lists all the items displayed in the Combobox Font style within the dialog box Font in Notepad application.
Function display_list(list_name$)
local i,msg$,s_exit
i=0
msg$=""
s_exit=0
repeat
    var$=ListItem$(list_name$,i)
    if var$="" then
        if i=0 then
            msgbox("ListBox or ComboBox not found",48,"ERROR")
            stop
        else
            s_exit=1
        endif
    else
        msg$=msg$+var$+"\n\"
        i=i+1
    endif
until s_exit=1 or i>40
msgbox(msg$,64,"The list contains : ")
endfunction

'launch notepad
Shell("notepad",1)
'Select Edit/Font menu
UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
ChooseMenu(Normal,"F&ormat|&Font...")
'Call display_list function for listing all the items for the Combobox named Font style.
'Combobox name is found using Spy.
display_list("NOTEPAD.EXE|ComboLBox|Font|2")
 
'close the dialog box and close Notepad
UseWindow("NOTEPAD.EXE|#32770|Font",1)
Click(Button,"Cancel")
CloseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)