Visual Basic 3.0 Does Not Pass Parameters by Reference

Last reviewed: July 30, 1997
Article ID: Q106642
The information in this article applies to:
  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, version 7.0

SUMMARY

Using a Microsoft Visual Basic 3.0 application, you cannot pass parameters "by reference." Visual Basic passes all parameters "by value."

Note: This is not a limitation of OLE Automation but of Visual Basic version 3.0. Visual Basic version 4.0 supports passing parameters by reference.

WORKAROUND

The quickest way to workaround this limitation is to surround the parameter being passed with parantheses, "()". For example:

   Word.FileOpen A$

passes the parameter by reference (default). Changing the command to:

   Word.FileOpen (A$)

forces the parameter to be passed by value. This will return the evaluated value.

MORE INFORMATION

When a value is passed as an argument to a subroutine by value, a copy of the data is passed to the subroutine. If the subroutine should alter the data, the variable in the calling subroutine will go untouched since it is working with copy of the data.

If a variable is passed as an argument to a subroutine by reference, the subroutine and the calling subroutine actually share the same variable. If the subroutine should alter the variable, the variable in the calling subroutine will also be altered. This is the default mechanism Word uses for parameter passing.


KBCategory: kbmacro
KBSubcategory:
Additional query words: 6.0 ole automation word object word6
6.0a 6.0c 7.0 word95 winword container position visual basic vb
word7
Keywords : kbmacro
Version : 6.0 6.0a 6.0c 7.0
Platform : WINDOWS


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: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.