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

est Math Operation Coercion Verify Sub
Entisoft Tools Port Module

Private Sub estMathOperationCoercionVerify()
    ' Illustrate the type of value returned from the built-in mathematical operations depending upon
    ' the types of the arguments.  Using the CoerceToType function seems to cause some of the built-in
    ' operators to promote the arguments differently, at least in the case of exponentiation.

    'See also:
    '  FixUps Class
    '  ConvertValues Class
    '  MathReals Class

    Dim astrOp() As String
    ReDim astrOp(1 To 5)

    astrOp(1) = "+"
    astrOp(2) = "-"
    astrOp(3) = "*"
    astrOp(4) = "/"
    astrOp(5) = "^"

    Dim aintVT() As Variant
    ReDim aintVT(1 To 6)

    aintVT(1) = vbInteger
    aintVT(2) = vbDate
    aintVT(3) = vbDouble
    aintVT(4) = vbLong
    aintVT(5) = vbSingle
    aintVT(6) = vbCurrency

    Dim intOp As Integer
    For intOp = LBound(astrOp) To UBound(astrOp)
        Dim intTypeOne As Integer
        For intTypeOne = LBound(aintVT) To UBound(aintVT)
            Dim intTypeTwo As Integer
            For intTypeTwo = LBound(aintVT) To UBound(aintVT)
                Dim strExpr As String
                Dim varRtn As Variant
    
                strExpr = "CoerceToType(1, " & aintVT(intTypeOne) & ") " & astrOp(intOp) & " CoerceToType(1, " & aintVT(intTypeTwo) & ")"
                Debug.Print VarTypeToString(aintVT(intTypeOne)) & " " & astrOp(intOp) & " " & VarTypeToString(aintVT(intTypeTwo)) & " = ";

                On Error Resume Next
                varRtn = estEvalWrap(strExpr)
                If Err Then
                    Debug.Print "(Error #" & Err & ": " & Error$ & ")";
                Else
                    Debug.Print VarTypeToString(VarType(varRtn));
                End If
                On Error GoTo 0
    
                Debug.Print
            Next intTypeTwo
        Next intTypeOne
    Next intOp
End Sub

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