|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
unexpected split functionality - index out of boundsI 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 Jeff wrote:
Show quoteHide quote > Hello all! How big is your text file? Check if it is the size of the file that is > > 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 > causing the problem than the format? 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.
Newbie Question: How To Open A File Non-Exclusively?
Web Service Deployment Issues Command line argument in NET Release Memory Prog execution in IDE works, fails when running exe Drag Picturebox Iterating thru User-Defined Data Type Property Threading reference Integer to color Multiple result sets from Data Reader |
|||||||||||||||||||||||