#156547 - 2006-02-03 10:43 AM
Re: Problem with @ERROR output -- yielding funny results...
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Add some code to check that your file opens have worked. Don't ever assume that anything will work, because at some point it won't.
Make sure that you are not trying to read past the end of any of your files.
If you are going to split a line you need to check the size of the array after the split. If you read a blank line, or a line which has less fields than you expect then there is a chance that the array is not as big as you were expecting. When you attempt to reference a cell past the end of the array you will get an "out of bounds" error.
If you don't want to check the size each time and the lines are of varying lengths then a trick I use is to add enough blank elements to the end of the line to ensure that the array reference will never be out of bounds.
For example the "+',,,,'" in the following code ensures that there is always at least 5 elements in the array, so that the next line can never cause an out-of-bounds error.
Quote:
$rArrLine = Split($rLine+',,,,',',') ? '1: ' + $rArrLine[4]
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|