This command is used to declare a function implemented in an external ScriptBasic library. Do NOT use this command to invoke a function from an external DLL that was not specifically written for ScriptBasic. When you include module BASIC files that contain DECLARE SUB lines, you can call the functions declared this way as they were entirely written in BASIC. You use/write a DECLARE SUB command if you developed an external module for ScriptBasic programs in C.
The difference between DECLARE SUB and DECLARE COMMAND is that the arguments passed to a function declared using DECLARE SUB evaluates its argument and passes the values to the C program implementing the function, whereas the functions declared using the command DECLARE COMMAND starts the function and evaluate the arguments one-by-one when and if the function implemented in C requests.
This difference is only important when you use expressions in the place of an argument that itself calls some other functions and has so called side effect. Have a look at the following code:
b = 1 + b
side_effect = b
b = 0
function side_effect() b = 1 + b side_effect = b end function
b = 0 print iff(0,side_effect(),2) print b
In the example above we use a hipotethical function implemented by a module and declared in the file iff.bas. This function evaluates the first argument and if that is true returns the second argument, otherwise it returns the third argument.
If the function iff was implemented as a command and declared accordingly using the command DECLARE COMMAND and if that module function evaluates only one of the second and third arguments then the global variable b remains unchanged.
If the function iff was implemented as a function and declared accordingly using the command DECLARE SUB and then the global variable b is increased.