Microsoft KB Archive/41535

= Syntax Differs When Calling a SUB without the CALL Keyword =

Article ID: 41535

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS

-



This article was previously published under Q41535



SUMMARY
When calling a SUBprogram in QuickBasic without the keyword &quot;CALL&quot; (by specifying just the SUB name and arguments), you must omit the parentheses around the parameter list. This is known as an &quot;implied CALL&quot; 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 INFORMATION
The normal form of the CALL statement is as follows: CALL mysub (arg1,arg2) In the above example, arg1 and arg2 are passed &quot;by reference.&quot; Passing &quot;by reference&quot; 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 &quot;by value&quot;: CALL mysub ((arg1),(arg2)) Passing a variable &quot;by value&quot; 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,arg2 The 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 query words: QuickBas BasicCom

Keywords: KB41535

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.