vbscriptruntime-error

vbscript Type mismatch error when calling function


I am running into the Type Mismatch error when I attempt to call a function I created.

Example:

Function DoThis(paramA, paramB, paramC)
    If paramA = "Something" Then
        DoThis = DoSomething
    ElseIf paramA = "This" Then 
        DoThis = DoSomethingDifferent
    Else
        DoThis = DoThisOtherThing   
    End If
End Function
Dim result: result = DoThis(valueA, ValueB, ValueC)

Can anyone see what my mistake could be? Other functions are working correctly. I have double checked the spelling by actually copying and pasting the function name where I call it. I have verified that the function name is not used anywhere else, i.e., as a constant or something else.

Note that when debugging this the ValType for all arguments is vbString. Also I am never able to enter the function, so it is not like I am debugging the function, enter it and then get the type mismatch.

ty.


Solution

  • VBScript has only one data type called a Variant. A Variant is a special kind of data type that can contain different kinds of information, depending on how it is used. Because Variant is the only data type in VBScript, it is also the data type returned by all functions in VBScript.

    There are some subtypes of data that a Variant can contain (e.g. Empty, Null, string, integer, object, array etc.) You can use some conversion functions to convert data from one subtype to another, if that conversion is not implicit in VBScript. Now, pay your attention to real, factual data subtype of True and vbTrue.

    The True keyword (boolean literal) has a value (inner representation) equal to -1.

    On the other hand, vbTrue is one of few built-in constants and, in despite of it's name, has a subtype of Integer! It's one of so-called Tristate Constants:

    Constant     Value  Description  
    vbUseDefault  -2    Use default from computer's regional settings.
    vbTrue        -1    True
    vbFalse        0    False
    

    I hope next code could make clear all above statements:

    Wscript.Echo _
     vbTrue, CStr( vbTrue), VarType( vbTrue), TypeName( vbTrue) , _
     vbNewLine, True, CStr( True), VarType( True), TypeName( True)
    

    However, used with If _condition_ Then ..., there are some particularities; in brief: The Then part of the If ... statement conditionally executes groups of statements only when a single test If condition is not False, i.e. any non-zero number esteems to be true, not only -1. Therefore you are able to use whatever variable or expression (numeric or string) you choose as long as the result is numeric...

    Summarizing: If _expr_ Then ... is the same as If CBool(_expr_) Then ...