#166451 - 2006-08-25 07:04 PM
Script error: array reference out of bounds!
|
ledzepe
Fresh Scripter
Registered: 2005-12-06
Posts: 26
|
Hi everyone and advance thanks for those would help. Here's my script, p.csv is a multi row/line file. I get the error "array reference out of bounds!" after it has read the whole file.
- - - - - - - - - - - Dim $Line[39] If Open(1,"p.csv",2) = 0
WHILE @ERROR = 0 $Line = Split(readline(1),",") ? $Line[0] + $Line[3] + $Line[19] + $Line[21] LOOP
endif
|
|
Top
|
|
|
|
#166454 - 2006-08-25 09:10 PM
Re: Script error: array reference out of bounds!
|
ledzepe
Fresh Scripter
Registered: 2005-12-06
Posts: 26
|
The p.csv file has 39 columns/elements. The script above displays columns 0,3,19 and 21 properly up to the very last row of data then displays the error above plus the line "? $Line[0] + $Line[3] + $Line[19] + $Line[21]". I should have added that earlier.
|
|
Top
|
|
|
|
#166455 - 2006-08-25 09:33 PM
Re: Script error: array reference out of bounds!
|
ledzepe
Fresh Scripter
Registered: 2005-12-06
Posts: 26
|
I got it, i added an "if $Line[0] = "" goto end1 endif" after the split command and that did the trick. i was getting the out of bounds error because it has reached the end of the row and there was nothing to display.
|
|
Top
|
|
|
|
#166458 - 2006-08-25 11:49 PM
Re: Script error: array reference out of bounds!
|
ledzepe
Fresh Scripter
Registered: 2005-12-06
Posts: 26
|
I added the line "? @error" after the split line and never got a value > 0. When I tried to redirectoutput to file there was a blank line at the top. Is that normal?
|
|
Top
|
|
|
|
#166459 - 2006-08-26 12:17 AM
Re: Script error: array reference out of bounds!
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
Yes, you're telling it to print a line by using ?
Here is some untested code to remove blank but still should do similar as Rad has already shown you.
Code:
WHILE @ERROR = 0 $Line = Split(readline(1),",") If $Line $Line[0] + $Line[3] + $Line[19] + $Line[21] ? EndIf LOOP
This would get rid of a blank but would still error if one of the elements of your array was empty because you're telling it to use or show something that does not exist which generates the error.
|
|
Top
|
|
|
|
#166460 - 2006-08-26 02:05 AM
Re: Script error: array reference out of bounds!
|
Benny69
Moderator
   
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
I don’t think it is necessary to define $Line as an array because I think the ‘Split()’ function does that for you every time it is used.
Code:
Dim $Line,$Element,$Output $Output = "" If Open(1,"p.csv",2) = 0 While @ERROR = 0 $Line = Split(ReadLine(1),",") If $Line For Each $Element in $Line $Output = $Output + $Element Next ? $Output EndIf Loop EndIf
|
|
Top
|
|
|
|
#166461 - 2006-08-26 02:42 PM
Re: Script error: array reference out of bounds!
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
benny your code doesn't actually do what he is trying to do, but I decided to golf it anyways  Code:
Dim $Element,$Output if 0 = Open(1,"p.csv") do For Each $Element in Split(ReadLine(1),",") $Output = $Output + $Element Next ? $Output until @ERROR EndIf
|
|
Top
|
|
|
|
#166462 - 2006-08-26 04:02 PM
Re: Script error: array reference out of bounds!
|
Benny69
Moderator
   
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
lonk you da man
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 764 anonymous users online.
|
|
|