VB and Sheridan controls

The script below shows how to select an item when the listbox is not a pure Windows listbox exposed to Windows API listbox functions.

 
'First a function which retrieves the text

'it uses an array

 

dim tab_item$(100)

'***********************************************

function recup_item(nom_fen$)

local buf, sortie, i, ret, item$, item_pred$

buf=#IgnoreErrors

#IgnoreErrors=1

 

sortie=0

item_pred$=""

i=0

 

'coma back to the first item

ret=usewindow(nom_fen$)

if ret=0 then

sendkeys("<Home>")

repeat

sendkeys("<Ctrl c>")

pause 2 ticks

item$=getclipboard$()

if item$<>item_pred$ then

tab_item$(i)=item$

item_pred$=item$

i=i+1

sendkeys("<Down>")

else

sortie=1

endif

until sortie=1

'come back to first item

sendkeys("<Home>")

endif

#IgnoreErrors=buf

recup_item=i

endfunction

'--------------------------------------------

'This function displays items

sub affich_item(nom_fen$)

local i,nb_item, mes$

mes$=""

i=0

nb_item=0

nb_item=recup_item(nom_fen$)

if nb_item <> 0 then

repeat

mes$=mes$+"\n\"+tab_item$(i)

i=i+1

until i=nb_item

else

mes$="No item found"

endif

msgbox(mes$,32,"List of items found")

endsub

'--------------------------------------------

'This function tests if item is there

function item_present(nom_item$,nom_fen$)

local nb_item, i, trouve

 

i=0

trouve=0

 

nb_item=recup_item(nom_fen$)

 

if nb_item<>0 then

repeat

if tab_item$(i)<>nom_item$ then

i=i+1

else

trouve=1

endif

until trouve=1 or i=nb_item

endif

if trouve=1 then

item_present=i

else

item_present=-1

endif

endfunction

'---------------------------------------------

'This function selects the specified item

function select_item(nom_item$,nom_fen$)

local buf, pos, i, ret

 

pos=0

i=0

 

pos=item_present(nom_item$,nom_fen$)

if pos <> -1 then

buf=#IgnoreErrors

#IgnoreErrors=1

ret=usewindow(nom_fen$)

if ret=0 then

ret=1

i=0

if pos > 0 then

repeat

sendkeys("<Down>")

i=i+1

until i=pos

endif

endif

#IgnoreErrors=buf

else

ret=0

endif

select_item=ret

endfunction

 

'***********************************************

' EXAMPLES

'***********************************************

fen$="TREETEST.EXE|SSTreeWndClass|Form1|1"

item_cherche$="Child Node # 12"

 

res=recup_item(fen$)

msgbox("there is : "+str$(res)+" items")

affich_item(fen$)

 

if select_item(item_cherche$,fen$)=1 then

msgbox("Item "+item_cherche$+" selected")

else

msgbox("Item "+item_cherche$+" not found")

endif