Kbase P10004: Array subscript is out of range. (26)
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/28/2008 |
|
Status: Verified
SYMPTOM(s):
Array subscript <value> is out of range. (26)
** Unable to update <filename> Field. (142)
Running code similar to:
DEFINE VARIABLE iArray AS INTEGER EXTENT 7 NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
REPEAT iCounter = 1 to 7:
iCounter = iCounter + 1.
iArray[iCounter] = iCounter.
END.
DISPLAY iArray.
CAUSE:
Manually incrementing the repeat loop counter at the beginning of each iteration makes the range of its values 2 through 8 and not 1 through 7. It also makes the incremental step 2 instead of the default 1.
In the above code, when the counter reaches 8, the error:
?Array subscript 8 is out of range. (26)?
is generated because there is no 8th element in the array.
And the error:
?Unable to update Field. (142)?
is generated because there is no iArray[8] field to assign.
FIX:
A. If we need to assign ALL the elements:
DEFINE VARIABLE iArray AS INTEGER EXTENT 7 NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
REPEAT iCounter = 1 to 7:
iArray[iCounter] = iCounter.
END.
DISPLAY iArray.
B. If we need to ONLY assign the EVEN numbered elements:
DEFINE VARIABLE iArray AS INTEGER EXTENT 7 NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
REPEAT iCounter = 2 to 7 BY 2:
iArray[iCounter] = iCounter.
END.
DISPLAY iArray.
C. If we need to ONLY assign the ODD numbered elements:
DEFINE VARIABLE iArray AS INTEGER EXTENT 7 NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
REPEAT iCounter = 1 to 7 BY 2:
iArray[iCounter] = iCounter.
END.
DISPLAY iArray.