Subscript out Of Range error
Posted: Thu Nov 01, 2012 3:58 pm
Why am I getting an subscript out of range error on this line?
AboveAve(N) = 0
My code:
DIM AnnIncome(40) AS INTEGER
' Variables used:
' T1$ H1$, H2$, D1$ Print images
' ST$, TL$ Print images
' PrevTotal Previous Total
' LineCt Line number
' PageCt Page number
' TotHours Total
' IDNum ID Number
' AnnIncome$ Annual Income
' NumPersons Number of Persons
' ***********************************************************************
' * PROGRAM MAINLINE *
' ***********************************************************************
CLS
GOSUB InitializeVariables
GOSUB PrintHeadings
GOSUB ProcessDetail
GOSUB CalculatePovertyLevel
GOSUB CalculateAboveAve
END
' ***********************************************************************
' * INITIALIZE VARIABLES *
' ***********************************************************************
InitializeVariables:
LET PageCt = 0
LET Rate = 0
LET Hours = 0
LET T1$ = " Income Survey PAGE ##"
LET H1$ = ""
LET H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
LET D1$ = " #### $#,###.## #"
LET ST$ = " / \ SUBTOTAL #"
LET TL$ = " TOTAL #"
LET MaxLines = 30
RETURN
' ***************************************************************************
' * LPRINT HEADINGS *
' ***************************************************************************
PrintHeadings:
LET PageCt = PageCt + 1 'Add to page counter
PRINT CHR$(12); 'Advance to tope of page
PRINT USING T1$; PageCt 'Print title line
PRINT
PRINT H1$ 'Print column headings, line 1
PRINT H2$ 'Print column headings, line 2
PRINT
LET LineCt = 0 'Reset line counter
RETURN
' **********************************************************************************
' PROCESS DATA
' ***********************************************************************************
ProcessDetail:
LET TotIncome = TotIncome + AnIncome(N) 'Calc total
LET TotBelowPov = TotBelowPov + BelowPov(N) 'Calc total below pov
LET AveIncome = TotIncome / 14 'Calc average income
LET PercentBelowPov = TotBelowPov / 14 * 100 'Calc % below pov
' *************************************************************************
' * READ DATA *
' *************************************************************************
ReadData:
READ IDNum, AnnIncome, NumPersons
DATA 2497, 12,500, 2
DATA 3323, 13,00, 5
DATA 4521, 18,210, 4
DATA 6789, 8,000, 2
DATA 5476, 6,000, 1
DATA 4423, 16,400, 3
DATA 6587, 25,000, 4
DATA 3221, 10,500, 4
DATA 5555, 15,000, 2
DATA 0085, 19,700, 3
DATA 3097, 20,000, 8
DATA 4480, 23,400, 5
DATA 0265, 19,700, 2
DATA 8901, 13,000, 3
RETURN
CalculatePovertyLevel:
IF NumPersons(N) <2> 2 THEN
PovertyLevel(N) = 8000 + (2000 * (NumPersons(N) - 2))
END IF
IF AnIncome(N) <PovertyLevel> AveIncome THEN
AboveAve(N) = 1
ELSE
AboveAve(N) = 0
END IF
NEXT N
RETURN
Also, how would I print this program as a 3-part report
AboveAve(N) = 0
My code:
DIM AnnIncome(40) AS INTEGER
' Variables used:
' T1$ H1$, H2$, D1$ Print images
' ST$, TL$ Print images
' PrevTotal Previous Total
' LineCt Line number
' PageCt Page number
' TotHours Total
' IDNum ID Number
' AnnIncome$ Annual Income
' NumPersons Number of Persons
' ***********************************************************************
' * PROGRAM MAINLINE *
' ***********************************************************************
CLS
GOSUB InitializeVariables
GOSUB PrintHeadings
GOSUB ProcessDetail
GOSUB CalculatePovertyLevel
GOSUB CalculateAboveAve
END
' ***********************************************************************
' * INITIALIZE VARIABLES *
' ***********************************************************************
InitializeVariables:
LET PageCt = 0
LET Rate = 0
LET Hours = 0
LET T1$ = " Income Survey PAGE ##"
LET H1$ = ""
LET H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
LET D1$ = " #### $#,###.## #"
LET ST$ = " / \ SUBTOTAL #"
LET TL$ = " TOTAL #"
LET MaxLines = 30
RETURN
' ***************************************************************************
' * LPRINT HEADINGS *
' ***************************************************************************
PrintHeadings:
LET PageCt = PageCt + 1 'Add to page counter
PRINT CHR$(12); 'Advance to tope of page
PRINT USING T1$; PageCt 'Print title line
PRINT H1$ 'Print column headings, line 1
PRINT H2$ 'Print column headings, line 2
LET LineCt = 0 'Reset line counter
RETURN
' **********************************************************************************
' PROCESS DATA
' ***********************************************************************************
ProcessDetail:
LET TotIncome = TotIncome + AnIncome(N) 'Calc total
LET TotBelowPov = TotBelowPov + BelowPov(N) 'Calc total below pov
LET AveIncome = TotIncome / 14 'Calc average income
LET PercentBelowPov = TotBelowPov / 14 * 100 'Calc % below pov
' *************************************************************************
' * READ DATA *
' *************************************************************************
ReadData:
READ IDNum, AnnIncome, NumPersons
DATA 2497, 12,500, 2
DATA 3323, 13,00, 5
DATA 4521, 18,210, 4
DATA 6789, 8,000, 2
DATA 5476, 6,000, 1
DATA 4423, 16,400, 3
DATA 6587, 25,000, 4
DATA 3221, 10,500, 4
DATA 5555, 15,000, 2
DATA 0085, 19,700, 3
DATA 3097, 20,000, 8
DATA 4480, 23,400, 5
DATA 0265, 19,700, 2
DATA 8901, 13,000, 3
RETURN
CalculatePovertyLevel:
IF NumPersons(N) <2> 2 THEN
PovertyLevel(N) = 8000 + (2000 * (NumPersons(N) - 2))
END IF
IF AnIncome(N) <PovertyLevel> AveIncome THEN
AboveAve(N) = 1
ELSE
AboveAve(N) = 0
END IF
NEXT N
RETURN
Also, how would I print this program as a 3-part report