473,387 Members | 1,476 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

lstCheckedInProjects.Items.RemoveAt(item)

End If

StreamReader.Close()

End If

Next
----------------- End Code -----------------
Aug 8 '08 #1
2 2371
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
11
by: steve smith | last post by:
Hi I'm still having some problems getting my head round this language. A couple of things don't seem to work for me. First I am trying to obtan a count of the number of words in a sting, so am...
3
by: Don | last post by:
My user control has a combobox with an arraylist attached to it along with custom add and remove methods. The "Add" method is working great. However I don't understand why the "Remove" method...
4
by: Kevin | last post by:
Hello. My app uses user-based menu generation where all of the menu items are loaded from a SQLServer 2k database when the user logs in to the app. All is well except I cannot get an Access Key to...
0
by: a | last post by:
I'm trying to delete an item from a collection, by clicking on a delete button in a GridView control. The item in the collection is stored in the Profile object (serialized as xml in the...
6
by: Jonathan | last post by:
Hi. I'm having trouble figuring out what I should be doing here. I'm trying to remove an object from a list. The function is: void Alive::FromRoom () { list<Alive>::iterator iter =...
2
by: Kela | last post by:
An interesting problem: I have a ListView with LabelEdit set to TRUE. When I change the label, I want to make some decisions as to whether the ListViewItem (that's just been edited) should stay in...
4
by: Jerad Rose | last post by:
I'm baffled by this -- is there not a typed object used for ComboBox Items? Best I can tell, all of the methods for ComboBox that accept an Item are of type Object. Why in the world is a...
3
by: Barkingmadscot | last post by:
I am stuck, i can workout how to remove lines from an array I have loading a text file (a Log), I know which lines a need, but the logs can be upto 30K sometimes bigger. I found trying to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.