By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,493 Members | 3,090 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,493 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

lstCheckedInProjects.Items.RemoveAt(item)

End If

StreamReader.Close()

End If

Next
----------------- End Code -----------------
Aug 8 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Steve,

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

For item = file_count - 1 to 0 Step -1

Kerry Moorman
"Steve" wrote:
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

lstCheckedInProjects.Items.RemoveAt(item)

End If

StreamReader.Close()

End If

Next
----------------- End Code -----------------
Aug 8 '08 #2

P: n/a
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.

"Steve" <si*******@gmail.comwrote in message
news:56**********************************@c58g2000 hsc.googlegroups.com...
>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

lstCheckedInProjects.Items.RemoveAt(item)

End If

StreamReader.Close()

End If

Next
----------------- End Code -----------------
Aug 10 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.