Compatible with:
DOS Maximite CMM MM150 MM170 MM+ MMX Picromite ArmiteL4
Armite F4 ArmiteH7 Picomite CMM2
Syntax:
CALL usersubname$ [,usersubparameters,....]
CALL(userfunname$, [,userfunparameters,....])
Description:
CALL usersubname$ [,usersubparameters,....] (sub) or
CALL(userfunname$, [,userfunparameters,....]) (function)
allows you to CALL
subroutines using a string variable for the subroutine/function name.
In many case it can allow you to get rid of complex SELECT and IF THEN ELSEIF
ENDIF clauses and is processed in a much more efficient way.
The “usersubname$” can be any string or variable or function that resolves
to the name of a normal user subroutine (not an in-built command).
The “usersubparameters” are the same parameters that would be used to call
the subroutine directly.
A typical use could be writing any sort of emulator where one of a large number
of subroutines should be called depending on some variable. It also allows a way
of passing a subroutine name to another subroutine or function as a variable.
Example
a$="firstsub"
mysub 8,9
CALL "mysub", SIN(RAD(90)),7
CALL a$,a$
'
SUB firstsub x$
PRINT x$," hello"
END SUB
SUB mysub a,b
PRINT a+b
END SUB
OUTPUT:
17
8
firstsub hello
Another example using arrays:
DIM calltable$(3) LENGTH 3 =
("add", "tak", "div", "mul")
c=10
d=5
FOR i=0 TO 3
caller calltable$(i),c,d
NEXT i
SUB caller a$, x, y
CALL a$, x, y
END SUB
SUB add a,b
PRINT a+b
END SUB
SUB tak a,b
PRINT a-b
END SUB
SUB div a,b
PRINT a/b
END SUB
SUB mul a,b
PRINT a*b
END SUB
Output:
15
5
2
50
Using calculated string variables:
DO
DO
k$ = INKEY$
LOOP UNTIL k$<>""
IF k$ >"0" AND k$<="9" THEN
CALL "mysub"+k$
ENDIF
LOOP UNTIL k$ = "Q" OR k$ = "q"
END
SUB mysub1
PRINT "one"
END SUB
SUB mysub2
PRINT "two"
END SUB
SUB mysub3
PRINT "three"
END SUB
SUB mysub4
PRINT "four"
END SUB
SUB mysub5
PRINT "five"
END SUB
SUB mysub6
PRINT "six"
END SUB
SUB mysub7
PRINT "seven"
END SUB
SUB mysub8
PRINT "eight"
END SUB
SUB mysub9
PRINT "nine"
END SUB
Last edited: 15 December, 2020