BUG: Optional Argument Default Value Breaks Binary Compatibility

Last reviewed: January 16, 1998
Article ID: Q176164
The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0

SYMPTOMS

Setting the default value of an Optional String argument to vbNullString causes the following error when the project is compiled with Binary Compatibility:

   "<procedure> in the <class> class module has arguments and/or a return
   type that is incompatible with a similar declaration in the
   version-compatible component"

RESOLUTION

Use quotation marks instead of vbNullString. For example:

   Optional myString as String = ""

You may also see the error:

    "Variable uses an automation type not supported in Visual Basic (Error
   458)."

This occurs when you attempt to set the default value of a Variant optional argument to Null. Avoid using any of the null-related constants (vbNull, vbNullString, etc.) when providing a default value for an optional argument.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

A project containing the specification of this default value returns an error stating that the method for which the argument is defined is not Binary Compatible. This problem is specific to the use of vbNullString. It does not affect default values for Optional arguments in general.

Steps to Reproduce Behavior

  1. Create a new ActiveX DLL project.

  2. Insert the following code into Class1:

          Public Function meth1(pf1 As String, Optional pf2 As String = _
    
              vbNullString) As Boolean
             'Sample method
          End Function
    
    

  3. From the File menu, select Make Project1.DLL.

  4. From the Project menu, select Project1 Properties.

  5. Change the name of the project to TestBinary.

  6. Click the Component Tab.

  7. Set the Version Compatibility to Binary Compatibility.

  8. Verify that TestBinary.dll is listed in the File Location Box at the bottom of the form.

  9. Close the Project Properties form, and select "Make TestBinary DLL" from the File menu. Note that the error occurs at this point.
Keywords          : vb5all VBKBAutomation VBKBAX VBKBComp VBKBDLL
Version           : WINDOWS:5.0
Platform          : WINDOWS
Issue type        : kbbug


================================================================================


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