Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems deleting files listed in listbox 1

Status
Not open for further replies.

wraygun

Programmer
Dec 9, 2001
272
US
I have a listbox populated with the full path of several items from a directory. I'm attempting to delete only the selected(checked) items using the following code.

Code:
Dim i As Long

If List1.ListIndex = -1 Then Exit Sub

For i = List1.ListCount - 1 To 0 Step -1
   If List1.Selected(i) = True Then
      Kill List1.Text
      List1.RemoveItem i
   End If
Next i

It works on 1 or 2 items if they are not consecutive in the list.(next to one another), but If I select all the items or 2 consecutive items, I get a File Not Found error and when I debug, the listbox text value is the item it most recently deleted. Any help would be greatly appreciated.

Thanks,
Harold


***You can't change your past, but you can change your future***
 
try this.

Code:
Dim i As Long

If List1.ListIndex = -1 Then Exit Sub

For i = List1.ListCount - 1 To 0 Step -1
   If List1.Selected(i) = True Then
      Kill list1.list(i)
      List1.RemoveItem i
   End If
Next i
 
Perfect. Thank you.

Harold

***You can't change your past, but you can change your future***
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top