unexpected split functionality - index out of bounds

J

Jeff

Hello all!

I created a successful program that reads data from a reliable
tab-delimited file - or so I thought. After getting everything to work
with small files, I changed the input to a larger file that was created
by the same program with the same format so hopefully there shouldnt be
any problem.

Unfortunately after the change, my program could no longer read in data
from the file. The split only populates the first element of the array.
Any attempt to read any other elements throws a ***Index was outside
the bounds of the array*** error.

I realize that the obvious solution is that the larger file must be an
invalid format, but Ive double and triple checked it and the only
difference is that one file has many, many more entries. In fact, the
the first 200 lines of each file are identical character for character.

oRead = oFile.OpenText("Library.txt") 'miniLib.txt works fine
oRead.ReadLine() 'first line contains
headers
While oRead.Peek <> -1
dim LineIn as string = oRead.ReadLine()
dim LineData() as string = split(LineIn, chr(9))

' LineData(0) is valid
' LineData(1) is not valid
' LineData(2) is not valid, etc...
...process LineData...
end while

The input files have 24 fields separated by tabs so LineData should be
defined up until LineData(23). Im clueless. Why is split() being mean?
Someone please help! Thanks!

Jeff
 
U

uttara

Jeff said:
Hello all!

I created a successful program that reads data from a reliable
tab-delimited file - or so I thought. After getting everything to work
with small files, I changed the input to a larger file that was created
by the same program with the same format so hopefully there shouldnt be
any problem.

Unfortunately after the change, my program could no longer read in data
from the file. The split only populates the first element of the array.
Any attempt to read any other elements throws a ***Index was outside
the bounds of the array*** error.

I realize that the obvious solution is that the larger file must be an
invalid format, but Ive double and triple checked it and the only
difference is that one file has many, many more entries. In fact, the
the first 200 lines of each file are identical character for character.

oRead = oFile.OpenText("Library.txt") 'miniLib.txt works fine
oRead.ReadLine() 'first line contains
headers
While oRead.Peek <> -1
dim LineIn as string = oRead.ReadLine()
dim LineData() as string = split(LineIn, chr(9))

' LineData(0) is valid
' LineData(1) is not valid
' LineData(2) is not valid, etc...
...process LineData...
end while

The input files have 24 fields separated by tabs so LineData should be
defined up until LineData(23). Im clueless. Why is split() being mean?
Someone please help! Thanks!

Jeff
How big is your text file? Check if it is the size of the file that is
causing the problem than the format?
 
J

Jeff

Nevermind. I just found out that some of the elements that were being
read in from the larger file had newlines in some of the fields where I
wasnt expecting them - screwing up everything else. thanks anyway to
those that would have helped.
 

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

Top