Signature (Visual Basic / VBA)
Public Function CoerceToVarType( _
ByVal vString As Variant _
, ByVal vVarType As Variant _
) As Variant
Code Example
CoerceToVarType(Chr$(1) + Chr$(1), vbInteger) = 257%
CoerceToVarType(Chr$(1) + Chr$(1) + Chr$(0) + Chr$(0), vbLong) = 257&
CoerceToVarType(Chr$(1) + Chr$(1), vbInteger) = CoerceToInteger(Chr$(1) + Chr$(1))
Parameters
| Parameter | Description |
|---|---|
| vString | The string whose leading characters are to be interpreted as the data type identified by vVarType. |
| vVarType | The data type to which the string vString will be coerced. Function returns Null if vVarType is Null or cannot be fixed up to a number. |
Notes & Version History
| Note | Function generates the Visual Basic Error "Illegal Function Call" if vString is shorter than the data type to which it is being coerced. |
| Note | Function uses the leftmost characters in vString when it is longer than target data type. |
| Note | This function first converts the string from Unicode to the default code page of the system (in most cases except for that of the Coercion to a Byte). |