<-- Previous || Up || Next -->

Fix Up To Type Function
Fix Ups Class

Public Function FixUpToType( _
      ByVal vValue As Variant _
    , ByVal vVarType As Variant _
    ) As Variant

"Fix Up Value To Data Type"
Convert one type of value to another data type.

Examples:
    VarType(2) = vbInteger
    FixUpToType(2, vbLong) = 2
    VarType(FixUpToType(2, vbLong)) = vbLong
    FixUpToType("234", vbLong) = 234
See also:
    PromoteToMostCapableDataType Function
    FixUpVariantToBooleanMandSub Subroutine
    FixUpVariantToByteMandFn Function
    FixUpVariantToCurrencyMandSub Subroutine
    FixUpVariantToDateMandFn Function
    FixUpVariantToDecimalMandSub Function
    FixUpVariantToDoubleMandSub Subroutine
    FixUpVariantToIntegerMandSub Subroutine
    FixUpVariantToLongMandSub Subroutine
    FixUpVariantToSingleMandSub Subroutine
    FixUpVariantToStringFn Function
vValue: The value whose data type is to be changed within the return value.
vVarType: The new data type to which the value vValue should be converted. Function returns Null if vVarType is Null or cannot be fixed up to a number. Function returns vValue unchanged if its data type is already vVarType.

This function uses complicated rules (as described below) to determine how to change the data type of the value.

String: Function will return an empty string if vVarType is vbString and vValue is Null. Function will convert numeric vValue values to strings. Function will return string vValue values unchanged.

Boolean: If vVarType is vbBoolean and vValue is a number, numeric string, date, and date string, vValue is converted to Boolean. Otherwise, if vVarType is Boolean, the function returns False.

Numeric: If vVarType is one of the numeric data types (like vbByte, vbInteger, vbDouble, etc.) and vValue is a number, numeric string, date, and date string, then vValue is converted to the specified data type. If vValue is not within the range of values that the data type vVarType can represent, then the function will generate an error. Otherwise, the function will return the value 0 (zero) within a Variant of type vVarType.

DataObject: Function will always return the object pointer Nothing if vVarType is vbDataObject or vbObject.

Empty: Function will always return an Empty Variant if vVarType is vbEmpty.

Error: Function supports vVarType values of vbError with numeric vValue values.

Null: Function will always return Null if vVarType is vbNull.

Object: Function will always return the object pointer Nothing if vVarType is vbObject or vbDataObject.

Function will return Null if vVarType does not represent one of the known Visual Basic data types.

v1.5 Change: This function has been extended to support the new Decimal data type in VB 6.0,

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.