ProvideX V8.20 > Language Reference > 2. Directives
140
GOSUB Directive
          Execute Subroutine
Format
GOSUB stmtref
Where:
stmtref
Program line number or label to transfer control to.
Description
Use GOSUB to access a subroutine embedded in your current program. The current
location in the program is saved on a stack and control is passed to the statement
number or label you specify (or if no statement exists with the number specified, to the
next higher statement). ProvideX continues execution from there until a RETURN is
executed. Then it returns control to the position saved on the stack.
If you want to exit from a GOSUB subroutine without returning to the calling point,
you can use the EXITTO directive to remove the return point from the stack. You must
use either a RETURN or an EXITTO directive to terminate each GOSUB subroutine.
Do not place a RETURN directive inside a FOR..NEXT loop or a WHILE..WEND loop.
There is no limit (apart from memory space) to the number of GOSUB..RETURN
entries that you can have on the stack.
Note: The BEGIN, CLEAR, RESET, STOP, and END directives reset all entries in the
GOSUB..RETURN stack.
See Also
RETURN Subroutine/Function Return, p.289
Called Procedures, User's Guide
Examples
D$="",D1$="",D2$=""
-:/
0100 INPUT "Enter starting date DD/MM/YY: ",D$
0110 GOSUB 1000
0120 LET D1$=D$
0130 INPUT "Enter ending date DD/MM/YY: ",D$
0140 GOSUB 1000
0150 LET D2$=D$
0160 PRINT "DONE"; STOP
1000 REM Subroutine
1010 IF LEN(D$)<>8 THEN GOTO 1090
1020 IF D$(3,1)<>"/" OR D$(6,1)<>"/" THEN GOTO 1090
1030 LET D=NUM(D$(1,2),ERR=1090),M=NUM(D$(4,2),ERR=1090),Y=NUM(D$(7,2),ERR=
1030:1090)
1040 IF D<1 OR D>31 THEN GOTO 1090
1050 IF M<1 OR M>12 THEN GOTO 1090
1060 RETURN
1090 PRINT "Invalid. Restart.."
1100 EXITTO 0100
-:RUN
Enter starting date DD/MM/YY: 05/03/99
Enter ending date DD/MM/YY: 31/03/99
-:DONE