by reference argument type mismatch vba code example

Example: ByRef argument type mismatch

' If you don't specify a type for a variable, the variable receives the default 
' type, Variant. This isn't always obvious. For example, the following code  
' declares two variables, the first, "MyVar", is a Variant; the second, 
' "AnotherVar", is an Integer.
Sub main()  
    Dim MyVar, AnotherVar As Integer ' MyVar->Variant, AnotherVar->Integer
    'Dim MyVar As Integer, AnotherVar As Integer ' Both are declared integers
    MyVar = 3.1415 
    Call SomeSub((MyVar)) 
End Sub
Sub SomeSub (MyNum As Integer) 
    MyNum = MyNum + MyNum 
End Sub

Tags:

Misc Example