Function Convert Values Class

ReplaceVarTypeWithValue

"Replace All Values Of A Specific Type With Another Value" Replaces all values which have a specific data type with another value. Returns all other values unchanged. Generally only supports numeric and string values.

Signature (Visual Basic / VBA)

Public Function ReplaceVarTypeWithValue( _
      ByVal vOriginal As Variant _
    , ByVal vVarType As Variant _
    , ByVal vReplace As Variant _
    ) As Variant

Code Example

    ReplaceVarTypeWithValue(1, vbString, Null) = 1
    ReplaceVarTypeWithValue(1, vbInteger, "Int") = "Int"
    ReplaceVarTypeWithValue("Int", vbString, 0) = 0
    ReplaceVarTypeWithValue(Null, vbNull, "") = ""

Parameters

Parameter Description
vOriginal The value whose data type is checked to see if it matches vVarType. Function returns vReplace if the data type of vOriginal matches vVarType. Function returns vOriginal otherwise. vOriginal must be an Empty, Null, numeric, String, or Array value.
vVarType One of the vb constants that represents a Visual Basic data type. vOriginal values of this data type will be replaced by vReplace.
vReplace The value which is returned instead of vOriginal if the VarType of vOriginal is vVarType. vReplace must be an Empty, Null, numeric, String, or Array value.

Notes & Version History

Note Example #4 is the same as the NullToBlank function.
Note This function is a more generalized version of the BlankToValue , EmptyToValue , and NullToValue functions.