vb.net Reading from Multiline Text Book and Removing it

vb.net Reading from Multiline Text Book and Removing it

Page 1 of 1

3 Replies - 1572 Views - Last Post: 20 April 2009 - 07:18 AM Rate Topic: -----

#1 nixdaemon000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-September 08

vb.net Reading from Multiline Text Book and Removing it

Posted 13 April 2009 - 02:38 PM

I have to copy a List of Books given below to a Multiline TextBox and then parse the BookName and Version to be stored in a varaiable called _BookName and _Version which i will use to store it in a database later. When a Line is successfully read i want to delete that particular line from the Multiline TextBox but i am getting "Index out of array exception". Can anyone help me thru' this.

I would appreciate any help. Below is the strings that are in Multiline Textbox and after that the code which i used.

BookName: Design Analysis, Version: 18
BookName: Metals and Non Metals, Version: 12
BookName: Surface Diagram, Version: 10
BookName: Elements and Compounds, Version: 10

---------------------------------------------------
Dim bookDetails As New List(Of String)(txtPBooks.Text.Split(Environment.NewLine))

For i As Integer = 0 To bookDetails.Count - 1

Dim myLists() As String = bookDetails(i).Split(",")

Dim _BookName, _Version As String

_BookName = myLists(0).ToString

_BookName = _BookName.Substring(_BookName.IndexOf(":") + 1)

_Version = myLists(1).ToString

_Version = _Revision.Substring(_Revision.IndexOf(":") + 1)

bookDetails.RemoveAt(i)

txtPBooks.Lines = bookDetails.ToArray

Next i


This post has been edited by nixdaemon000: 13 April 2009 - 05:22 PM


Is This A Good Question/Topic? 0
  • +

Replies To: vb.net Reading from Multiline Text Book and Removing it

#2 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: vb.net Reading from Multiline Text Book and Removing it

Posted 13 April 2009 - 04:57 PM

Put code between Code tags. See CODE button on post editor.

Did you leave some words out of that error message? Could it have been more like "Index was outside the bounds of the array". If so, problem is fairly straight forward, the row/column index at some point in the loop is outside the boundaries of the array you want to read.
Was This Post Helpful? 0
  • +
  • -

#3 LemonMan  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 170
  • Joined: 22-August 05

Re: vb.net Reading from Multiline Text Book and Removing it

Posted 14 April 2009 - 08:50 AM

The problem is that you are deleting say item 5 when there are six items to begin with. When the program goes to delete item 6, it doesn't exist becuase 6 is now 5.

Try this:

Dim bookDetails As New List(Of String)(txtPBooks.Text.Split(Environment.NewLine))

Do Until bookDetails.Count = 0

Dim myLists() As String = bookDetails(0).Split(",")

Dim _BookName, _Version As String

_BookName = myLists(0).ToString

_BookName = _BookName.Substring(_BookName.IndexOf(":") + 1)

_Version = myLists(1).ToString

_Version = _Revision.Substring(_Revision.IndexOf(":") + 1)

bookDetails.RemoveAt(0)

txtPBooks.Lines = bookDetails.ToArray

Loop


Was This Post Helpful? 1
  • +
  • -

#4 nixdaemon000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-September 08

Re: vb.net Reading from Multiline Text Book and Removing it

Posted 20 April 2009 - 07:18 AM

Thank you very much LemonMan. Problem is solved.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1