Syntax Differs When Calling a SUB without the CALL Keyword

Last reviewed: February 16, 1995
Article ID: Q41535

SUMMARY

When 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 INFORMATION

The 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,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 reference words: QuickBas BasicCom
KBCategory: kbprg
KBSubcategory:


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 16, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.