Syntax Differs When Calling a SUB without the CALL Keyword (41535)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5

This article was previously published under 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
				

Modification Type:MinorLast Reviewed:1/9/2003
Keywords:KB41535