Syntax Differs When Calling a SUB without the CALL KeywordLast reviewed: February 16, 1995Article ID: Q41535 |
SUMMARYWhen calling a SUBprogram in QuickBasic without the keyword "CALL" (by specifying just the SUB name and arguments), you must omit the parentheses around the parameter list. This is known as an "implied CALL" statement. You must also declare that procedure in a DECLARE statement. This information applies to Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50, Microsoft Basic Compiler Versions 6.00 and 6.00b, and Microsoft Basic PDS Version 7.00. Earlier versions of these products do not support the implied CALL syntax.
MORE INFORMATIONThe normal form of the CALL statement is as follows:
CALL mysub (arg1,arg2)In the above example, arg1 and arg2 are passed "by reference." Passing "by reference" means that if the subprogram changes the values of the passed parameters, they are passed back changed. If an individual parameter is placed inside parentheses, the parameter is passed "by value":
CALL mysub ((arg1),(arg2))Passing a variable "by value" means that only its value is passed, and the value of the variable in the calling program is not changed by assignments in the SUBprogram. If the CALL statement is omitted from the line (i.e., only the SUB name is given to indicate the CALL), then the outermost parentheses must be omitted. The proper syntax for a call by reference without the CALL keyword is as follows:
mysub arg1,arg2The proper syntax for a call by value without the CALL keyword is as follows:
mysub (arg1),(arg2)The following is an example of the difference between calling by reference and by value:
DECLARE SUB mysub (arg1, arg2) arg1 = 5 arg2 = 6 mysub arg1, arg2 ;call by reference PRINT arg1, arg2 ;results in 1 and 2 arg1 = 5 mysub (arg1), (arg2) ;call by value PRINT arg1, arg2 ;results in 5 and 6 END SUB mysub (arg1, arg2) arg1 = 1 arg2 = 2 END SUB |
Additional reference words: QuickBas BasicCom
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |