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

unexpected split functionality - index out of bounds

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

Feb 2 '06 #1
Share this Question
Share on Google+
2 Replies


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

Feb 2 '06 #2

P: n/a
Jeff wrote:
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?
Feb 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.