English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

sir in visual basic 6.0 i have made an application which contains the listbox .The multiselect property of the listbox is set as the simple select.I have a button on it to remove the selected items .The coding of this button is following
dim i as integer
if list1.selcount=1 then
list1.removeitem i
else if list1.selcount>1 then
for i=0 to list1.listcount-1
if list1.selected(i) then
list1.removeitem i
end if
next
end if
but this code generates an error and when i scan the lisbox backward (for i=list1.listcount-1 to 0 step -1) then it does not generates an error.why explain it.please help.

2007-05-24 02:12:46 · 1 answers · asked by Zia ur Rahman 1 in Computers & Internet Programming & Design

1 answers

Every time you remove an item from the list you also cause the list count to be modified. As you are using Listcount in the for/Next you may be creating the error as the listcount is reduced

Try assigning the ListCount to a variable BEFORE you enter the For?Next loop.

CNT = listbox1.count

For i = CNT to 0 STEP -1

Try that and see if you still get the error.

2007-05-24 04:38:51 · answer #1 · answered by MarkG 7 · 1 0

fedest.com, questions and answers