Remove item(s) from list box based upon string in text file



I am working on a program that works like a check in/check out
system. There is a folder on a network drive that stores a bunch of
vb programs. This program will check in and check out programs and
store them locally on the user's machine. I want to be able to tell
if a program is checked in or checked out. I am doing this by writing
to a text file a 1 if it is checked in or a 0 if it is checked out. I
am using StreamReader to read the first line in the text file and
storing the value in a string (status). I think what I am doing wrong
is that I am getting the total number of items in this list box and
when I remove an item from the list box, the total number of items in
the list box doesn't reflect an item being removed. This is the error
I am getting:

InvalidArgument=Value of '4' is not valid for 'index'.
Parameter name: index

I am stuck with trying to re-initialize my count to show that an item
has been removed. Any suggestions would be greatly appreciated.

I am using Visual Basic 2005 Express, Framework 2.0.

-----------------Begin Code-----------------
file_count = lstCheckedInProjects.Items.Count

For item = 0 To file_count - 1

If Directory.Exists(DestPath &
lstCheckedInProjects.Items(item).ToString) Then

StreamReader = New StreamReader(DestPath &
lstCheckedInProjects.Items(item).ToString & "\" & status_file)

status = StreamReader.ReadLine()

If status = "0" Then


End If


End If

----------------- End Code -----------------

Kerry Moorman


For that to work you would need to run your loop like this:

For item = file_count - 1 to 0 Step -1

Kerry Moorman

James Hahn

How many times can the item appear in the list? If it can appear once only,
then simply exit the FOR loop as soon as the item is found and removed.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question