|
-
Oct 18th, 2000, 03:02 AM
#1
Thread Starter
Frenzied Member
I can't figure it out anymore
--
My prob:
The user can add files to a listbox to let 'm run in the program (in a batch-sequence) but ofcourse I have to let the user delete files he doesn't need to be parsed.
but....
when I try to delete a item in a selected() way it gives me an error..
--
If lList.ListCount = 1 Then
lList.RemoveItem (lList.ListIndex)
Else
For I = 0 To (lList.ListCount)
If lList.Selected(I) = True Then
lList.RemoveItem (I)
End If
Next I
End If
Most of the time if I = 2 then it crashes...
What am I doin' wrong here?
Thnx in advance;
-
Oct 18th, 2000, 03:46 AM
#2
transcendental analytic
the items are indexed so that the 0 counts and the last one is lListcount -1
Code:
For I = 0 To (lList.ListCount) -1
If lList.Selected(I) = True Then
lList.RemoveItem (I)
End If
Next I
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 18th, 2000, 03:53 AM
#3
Thread Starter
Frenzied Member
Tried... Crashed.
I solved it in a very cruel way though 
--
On Error Resume Next
lList.ListIndex = -1
For I = -1 To (lList.ListCount - 1)
If lList.Selected(I) = True Then lList.RemoveItem I
Next I
I = 0
If lList.Selected(I) = True Then lList.RemoveItem I
On Error GoTo 0
--
It crashes on the Selected(I) (I is that at that point 0).. so I presume it crashes because the list index is updated at that point and that the Index says there is a 2 but it's now 1 or 0
(removing more then one option)
Did that make sense? 
-
Oct 18th, 2000, 06:11 AM
#4
Other code?
What other Subs you have that might affect when item is selected or something?
If there's any, you should do somehow so that nothing else wouldn't be checked when deleting items.
Hope this helps,
-
Oct 18th, 2000, 06:46 AM
#5
Thread Starter
Frenzied Member
Nothing interferes with the list box except the sub mentioned above.
-
Oct 18th, 2000, 07:15 AM
#6
The way to remove multiple items from a listbox is to loop backwards thru the listbox - otherwise, your loop counter will get out of sync with the listindexes and cause you the problems that you describe.
Try this:
Code:
For I = (lList.ListCount -1) To 0 Step -1
If lList.Selected(I) = True Then
lList.RemoveItem (I)
End If
Next I
"It's cold gin time again ..."
Check out my website here.
-
Oct 18th, 2000, 07:20 AM
#7
Thread Starter
Frenzied Member
That should do the trick; Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|