Page 1 of 1 1
Topic Options
#133817 - 2005-02-15 03:31 PM Array reference out of bounds... don't know why
bcambre Offline
Fresh Scripter

Registered: 2004-12-07
Posts: 14
Any idea why my Array reference gets out of bounds?
Code:

IF Open(3, $PATHTOFIXES+$UPDATELIST) = 0
$x = ReadLine(3)
;? "Line read 1 : " + $x ?
WHILE @ERROR = 0
$myarray=Split($x,",")
$yesno=trim($myarray[0])
$patchfile=trim($myarray[1])
$regfile=trim($myarray[2])
$updopt=trim($myarray[3])
if $updopt = 2 $UPDATEOPTIONS= " /q" endif
if $yesno = "y"
? "-------------------------------------------------------------------------------------"
? " Patchfile : " + $patchfile
? " Regfile : " + $regfile
? " Update Options : " + $UPDATEOPTIONS
?
If KeyExist($regfile)=1
? " Update exists..."
Else
? " Update needed..."
If Exist($PATHTOFIXES+$PATCHFILE)
"updating now..."
$execute="$PATHTOFIXES"+$PATCHFILE+$UPDATEOPTIONS
SHELL 'CMD.EXE /C "$execute"'
Else
? " Patch file [" + $PATCHFILE + "] not found."
Endif
Endif
?
Endif
$x = ReadLine(3)
LOOP
$x=Close (3)
ELSE
BEEP
? "Config file not opened, error code: [" + @ERROR + "]"
ENDIF



Added code tags - Bullock


Edited by Howard Bullock (2005-02-15 05:38 PM)
_________________________
bram

Top
#133818 - 2005-02-15 03:56 PM Re: Array reference out of bounds... don't know why
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Your code is too optimistic. You do not factor that $x may not Split() out to 4 elements.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#133819 - 2005-02-15 03:59 PM Re: Array reference out of bounds... don't know why
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Please put your script in "code" tags - it makes it much easier to read.

You need to put in a check to ensure that there are enough elements in the array.

Either:
Code:
WHILE @ERROR = 0

$myarray=Split($x,",")
If UBound($myarray)>=3
; Do the updates
Else
"Not enough elements in '"+$x+"'" ?
EndIf
Loop



Top
#133820 - 2005-02-15 04:07 PM Re: Array reference out of bounds... don't know why
bcambre Offline
Fresh Scripter

Registered: 2004-12-07
Posts: 14
"optimistic code", I like that one
The "If UBound($myarray)>=3" thing worked.
I always miss the obvious things... not that much of a programmer.
Thanks a lot guys.
_________________________
bram

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 363 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.05 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org