Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
DECLARE Statement (BASIC Procedures) Programming Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
'Example 1 uses the DECLARE statement to allow a SUB procedure to be
'invoked without using the CALL keyword.
'
'Example 2 uses the BYVAL keyword to pass an argument by value.
'
'*************************************************************
'* Example 1:
'*************************************************************
DECLARE SUB Sort (A() AS INTEGER, N AS INTEGER)
DIM Array1(1 TO 20) AS INTEGER
DIM I AS INTEGER
'Generate 20 random numbers.
RANDOMIZE TIMER
FOR I% = 1 TO 20
Array1(I%) = INT(RND * 100)
NEXT I%
'Sort the array, calling Sort without the CALL keyword. Notice the
'absence of parentheses around the arguments in the call to Sort.
Sort Array1(), 20
'Print the sorted array.
CLS
FOR I% = 1 TO 20
PRINT Array1(I%)
NEXT I%
END
'Sort procedure.
SUB Sort (A%(), N%)
FOR I% = 1 TO N% - 1
FOR J% = I% + 1 TO N%
IF A%(I%) > A%(J%) THEN SWAP A%(I%), A%(J%)
NEXT J%
NEXT I%
END SUB
'***************************************************************
'* Example 2:
'***************************************************************
DECLARE SUB Mult (BYVAL X!, Y!)
CLS
a = 1
b = 1
PRINT "Before subprogram call, A = "; a; ", B ="; b
' A is passed by value, and B is passed by reference:
CALL Mult(a, b)
PRINT "After subprogram call, A ="; a; ", B ="; b
END
SUB Mult (BYVAL X, Y)
X = 2 * X
Y = 3 * Y
PRINT "In subprogram, X ="; X; " , Y ="; Y
END SUB