Remove item(s) from list box by checking a code in a text file

Checks for a code in a text file to determine if the item should be re

Page 1 of 1

2 Replies - 4865 Views - Last Post: 11 August 2008 - 08:43 AM Rate Topic: -----

#1 sithius92  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 36
  • View blog
  • Posts: 164
  • Joined: 01-August 08

Remove item(s) from list box by checking a code in a text file

Posted 08 August 2008 - 12:29 PM

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.

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


This post has been edited by sithius92: 08 August 2008 - 02:06 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Remove item(s) from list box by checking a code in a text file

#2 ahmad_511  Icon User is offline

  • MSX
  • member icon

Reputation: 131
  • View blog
  • Posts: 722
  • Joined: 28-April 07

Re: Remove item(s) from list box by checking a code in a text file

Posted 08 August 2008 - 10:26 PM

hello,
file_count = lstCheckedInProjects.Items.Count
dim itemIndex as integer=0
        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(itemIndex)
                    else
                         itemIndex=itemIndex+1
                End If

                StreamReader.Close()

            End If

        Next



Was This Post Helpful? 1
  • +
  • -

#3 sithius92  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 36
  • View blog
  • Posts: 164
  • Joined: 01-August 08

Re: Remove item(s) from list box by checking a code in a text file

Posted 11 August 2008 - 08:43 AM

View Postahmad_511, on 9 Aug, 2008 - 12:26 AM, said:

hello,
file_count = lstCheckedInProjects.Items.Count
dim itemIndex as integer=0
        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(itemIndex)
                    else
                         itemIndex=itemIndex+1
                End If

                StreamReader.Close()

            End If

        Next




Thanks for your help. I was able to get it working.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1