PRB: Parameter Type Mismatch When Don't Pass Property By Val (90900)



The information in this article applies to:

  • Microsoft Professional Toolkit for Microsoft Visual Basic programming system for Windows
  • Microsoft Visual Basic Standard Edition for Windows 1.0
  • Microsoft Visual Basic for MS-DOS

This article was previously published under Q90900

SYMPTOMS

When using a property of a control as an argument to a SUB or FUNCTION statement, make sure that the property is passed by value, not by reference. If you do not, you may receive the error message
Parameter type mismatch

STATUS

This behavior is by design.

MORE INFORMATION

Not all properties of all controls require passing by value, but most do. For compatibility with any type of control property, you should pass by value. You can pass the parameter by value in one of two ways:

  • You can define the parameter ByVal in the SUB definition:
        SUB Sub1(ByVal x AS INTEGER, y AS INTEGER)
           PRINT x, y
        END SUB
        Call Sub1(Check1.Value, 10)
    						
  • You can pass the parameter argument by value in the Call by placing parentheses "()" around the argument.
       SUB Sub1(x AS INTEGER, y AS INTEGER)
          PRINT x, y
       END SUB
       Call Sub1((Check1.Value), 10)

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:kbprb KB90900 kbAudDeveloper