ListItem$

Windows management function.

The ListItem$ function returns an item from the specified listbox or combobox.

Usage

Retrieves the text content of an item in a listbox or combobox. Only standard Windows list/combo will 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>,<n>)

Parameters

<window_name>, string, window name of the listbox or combobox in which to find the <n>th item. First item starts at 0.

Return value

var$, string, return value which contains the <n>th item from the listbox or combobox. If the item does not exist, an empty string is returned.

See also

VB and Sheridan controls not recognized by ListItem$

Example

 

var$=ListItem$("EXPLORER.EXE|ComboBox|Run|1",1)

Example code

This script displays 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 menu Edit, option Set Font

UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)

ChooseMenu(Normal,"F&ormat|&Font...")

 

'function call 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)