Is it possible to write a subroutine or function with optional arguments?
for example:
MyFunct (x AS INTEGER, [y AS INTEGER, Z AS INTEGER])
so that I can use the function with only the first argument and sometimes with all arguments, in the same program, like the following for example:
Myfunct 5
MyFunct 5,6,7
Also, is it possible to write a sub or a function that takes arguments in format that is used with some of the graphics commands in QuickBasic, like the WINDOW and LINE.. For example:
WINDOW (10,50)-(100,100)
LINE (10,10)-(50,50
I tried using square brackets, [], because the manual said those represent the optional arguments, but I guess it is only for reading the syntax conventions. Is there any way to have optional arguments?
So, the way I would do it would be to pass your arguments in a string, separated by some delimiter. Then you can break the variables out of the string once in the function with logic to handle if the argument is missing.
MyFunc (“x=1,y=2,z=3”)
String parser left as an exercise for the OP