What does it mean if you get an error stating "Subscript out Of Range"?
How would I fix it on this code:
' Initialize variables
Pieces = -1
Pay# = 0
TotPieces = 0
TotPay = 0
T1$ = "PIECEWORK WEEKLY REPORT"
H1$ = "NAME" + SPC$(16) + "Pieces" + SPC$(6) + "Pay"
D1$ = ""
TL$ = ""
Name$ = ""
'Get first worker name
INPUT "PLEASE ENTER YOUR NAME OR TYPE 'END' TO QUIT"; Name$
DO
'Get worker pieces
INPUT "PLEASE ENTER THE NUMBER OF PIECES OR TYPE 'END' TO QUIT"; Pieces
'Calculate rate
IF Pieces >= 600 THEN
Rate = 65
ELSEIF Pieces >= 400 AND Pieces <599>= 200 AND Pieces <399>= 1 AND Pieces <= 199 THEN
Rate = 5
ELSE Rate = 0
END IF
'Calculate pay
IF Rate > 0 THEN Pay = Pieces * Rate ELSE Pay = 0
'Running Totals
TotPieces = TotPieces + Pieces
TotPay = TotPay + Pay
PayF$ = " "
RSET PayF$ = STR$(Pay)
D1$ = D1$ + Name$ + SPC$(20 - LEN(Name$)) + STR$(Pieces) + SPC$(10 - LEN(STR$(Pieces))) + PayF$ + CHR$(13)
'Get next worker or END to quit
INPUT "PLEASE ENTER YOUR NAME"; Name$
LOOP UNTIL UCASE$(Name$) = "END"
'Clear screen
CLS
' Write headings
PRINT TAB(10); T1$
PRINT H1$
'Print report detail
PRINT D1$
ToTPayF$ = " "
RSET ToTPayF$ = STR$(TotPay)
PRINT " TOTALS" + SPC$(12) + STR$(TotPieces) + SPC$(10 - LEN(STR$(TotPieces))) + ToTPayF$
END
'**********************************************************************
its happening at the "H1$ = "NAME" + SPC$(16) + "Pieces" + SPC$(6) + "Pay" line
Subscript out Of Range??
'SUBSCRIPTION OUT OF RANGE' IT'S AN ERROR WHEN YOU OPEN A MATRIX AND
YOU TRY TO USE THAT MATRIX BEYOND THE LIMITS. FOR EXAMPLE IF YOU OPENED...
DIM AAA(100) AS INTEGER
AND AFTER THAT YOU TRY TO DO THIS...
AAA(101) = 22222
THEN YOU WILL HAVE THE ERROR 'SUBSCRIPTION OUT OF RANGE'
THE FUNCTION SPC() IT DOESN'T NEED THE STRINGS SIGN: '$' BECAUSE
THE COMPILER WILL THINK THAT IT IS A MATRIX. YOU LINE MUST BE:
YOU TRY TO USE THAT MATRIX BEYOND THE LIMITS. FOR EXAMPLE IF YOU OPENED...
DIM AAA(100) AS INTEGER
AND AFTER THAT YOU TRY TO DO THIS...
AAA(101) = 22222
THEN YOU WILL HAVE THE ERROR 'SUBSCRIPTION OUT OF RANGE'
THE FUNCTION SPC() IT DOESN'T NEED THE STRINGS SIGN: '$' BECAUSE
THE COMPILER WILL THINK THAT IT IS A MATRIX. YOU LINE MUST BE:
Code: Select all
H1$ = "NAME" + SPC(16) + "Pieces" + SPC(6) + "Pay"
MY PAGE: http://Qbasic.phatcode.net" target="_blank
(I ONLY USE WINDOWS 98SE YET, BELIEVE IT OR NOT)
(I ONLY USE WINDOWS 98SE YET, BELIEVE IT OR NOT)
-
- Coder
- Posts: 42
- Joined: Mon Sep 03, 2012 4:32 pm
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
SPC$ denotes a STRING ARRAY. SPC prints spaces!
Code: Select all
' Initialize variables
Pieces = -1
Pay# = 0
TotPieces = 0
TotPay = 0
T1$ = "PIECEWORK WEEKLY REPORT"
H1$ = "NAME" + SPC(16) + "Pieces" + SPC$(6) + "Pay"
D1$ = ""
TL$ = ""
Name$ = ""
'Get first worker name
INPUT "PLEASE ENTER YOUR NAME OR TYPE 'END' TO QUIT"; Name$
DO
'Get worker pieces
INPUT "PLEASE ENTER THE NUMBER OF PIECES OR TYPE 'END' TO QUIT"; Pieces
'Calculate rate
IF Pieces >= 600 THEN
Rate = 65
ELSEIF Pieces >= 400 AND Pieces <599>= 200 AND Pieces <399>= 1 AND Pieces <= 199 THEN
Rate = 5
ELSE Rate = 0
END IF
'Calculate pay
IF Rate > 0 THEN Pay = Pieces * Rate ELSE Pay = 0
'Running Totals
TotPieces = TotPieces + Pieces
TotPay = TotPay + Pay
PayF$ = " "
RSET PayF$ = STR$(Pay)
D1$ = D1$ + Name$ + SPC(20 - LEN(Name$)) + STR$(Pieces) + SPC$(10 - LEN(STR$(Pieces))) + PayF$ + CHR$(13)
'Get next worker or END to quit
INPUT "PLEASE ENTER YOUR NAME"; Name$
LOOP UNTIL UCASE$(Name$) = "END"
'Clear screen
CLS
' Write headings
PRINT TAB(10); T1$
PRINT H1$
'Print report detail
PRINT D1$
ToTPayF$ = " "
RSET ToTPayF$ = STR$(TotPay)
PRINT " TOTALS" + SPC(12) + STR$(TotPieces) + SPC$(10 - LEN(STR$(TotPieces))) + ToTPayF$
END
'**********************************************************************
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
-
- Coder
- Posts: 42
- Joined: Mon Sep 03, 2012 4:32 pm
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Yeah, QB requires SPACE$ in string definitions. SPC is suppposed to be used to move the invisible PRINT cursor on the screen. I also took off the END exit option because the INPUT requires a number, not a string! If you type END instead of a number it will REDO FROM START.
You could use a string variable for the number INPUT and use VAL to convert it to a number if it is not "END". VAL("END") = 0 so you could also exit if the number value is 0...
You could use a string variable for the number INPUT and use VAL to convert it to a number if it is not "END". VAL("END") = 0 so you could also exit if the number value is 0...
Code: Select all
' Initialize variables
Pieces = -1
Pay# = 0
TotPieces = 0
TotPay = 0
T1$ = "PIECEWORK WEEKLY REPORT"
H1$ = "NAME" + SPACE$(16) + "Pieces" + SPC$(6) + "Pay"
D1$ = ""
TL$ = ""
Name$ = ""
'Get first worker name
INPUT "PLEASE ENTER YOUR NAME OR TYPE 'END' TO QUIT: "; Name$
DO
'Get worker pieces
INPUT "PLEASE ENTER THE NUMBER OF PIECES: "; Pieces
'Calculate rate
IF Pieces >= 600 THEN
Rate = 65
ELSEIF Pieces >= 400 AND Pieces <599>= 200 AND Pieces <399>= 1 AND Pieces <= 199 THEN
Rate = 5
ELSE Rate = 0
END IF
'Calculate pay
IF Rate > 0 THEN Pay = Pieces * Rate ELSE Pay = 0
'Running Totals
TotPieces = TotPieces + Pieces
TotPay = TotPay + Pay
PayF$ = " "
RSET PayF$ = STR$(Pay)
D1$ = D1$ + Name$ + SPACE$(20 - LEN(Name$)) + STR$(Pieces) + SPC$(10 - LEN(STR$(Pieces))) + PayF$ + CHR$(13)
'Get next worker or END to quit
INPUT "PLEASE ENTER YOUR NAME"; Name$
LOOP UNTIL UCASE$(Name$) = "END"
'Clear screen
CLS
' Write headings
PRINT TAB(10); T1$
PRINT H1$
'Print report detail
PRINT D1$
ToTPayF$ = " "
RSET ToTPayF$ = STR$(TotPay)
PRINT " TOTALS" + SPACE$(12) + STR$(TotPieces) + SPC$(10 - LEN(STR$(TotPieces))) + ToTPayF$
END
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
-
- Coder
- Posts: 42
- Joined: Mon Sep 03, 2012 4:32 pm