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

Fix Up Bitwise Arguments Function
Bitwise Class

Public Function FixUpBitwiseArguments( _
      ByRef rFixUpToType As Variant _
    , ByRef rOne As Variant _
    , ByRef rTwo As Variant _
    ) As Boolean

Fix up the arguments to String values suitable for use with the bitwise functions that require two operands, and also determine the type of value that should be returned by the calling function.

Both arguments are usually fixed up to String values, but those String values are constructed differently depending upon the types of the two values.
Example:
    Assuming
       Dim varRtnType As Variant
       Dim varOne As Variant
       Dim varTwo As Variant
       varOne = 23
       varTwo = -23
    for example
       FixUpBitwiseArguments(varRtnType, varOne, varTwo)
    leaves
       varRtnType = vbInteger
       varOne = Chr$(23) + Chr$(0)
       varTwo = Chr$(233) + Chr$(255)
See also:
    FixUps Class
rOne: First of the two arguments which is to be fixed up to a String.
rTwo: Second of the two arguments which is to be fixed up to a String.
rFixUpToType: The type of value that should be returned by the function that called FixUpBitwiseArguments as determined by this function based upon the type of the arguments rOne and rTwo. For example, if both arguments are two-byte Integer values, this function will convert both arguments to two-character String values, and it will set rFixUpToType to vbInteger to tell the calling function that it should coerce the result of its operations on the fixed-up Strings back to an Integer value.
To summarize: If both arguments are String values, then their most significant bytes are aligned and the calling function should return a String value. If both arguments are numeric, then their least significant bytes are aligned and rFixUpToType will be set to an appropriately-capable numeric type. If one argument is a String and one is numeric, then the bytes of the number are reversed, their least-significant bytes are aligned, and the calling function should return a String.

If rOne is Null, the function returns False and sets rFixUpToType to Null (so that the function calling function can easily support three-valued logic by returning this value).

If rTwo is Null, the function returns False and sets rFixUpToType to Null. (so that the function calling function can easily support three-valued logic by returning this value).

If both rOne and rTwo are empty, the function returns False and sets rFixUpToType to Empty. (so that the function calling function can easily support three-valued logic by returning this value).

If rOne is empty, rTwo will be coerced to a String, rOne will be changed to a Nil character (Chr$(0)) filled String of the same length, and rFixUpToType will be set to the type of rTwo.

If rTwo is empty, rOne will be coerced to a String, rTwo will be changed to a Nil character (Chr$(0)) filled String of the same length, and rFixUpToType will be set to the type of rOne.

If either rOne or rTwo is a String, rFixUpToType will be set to vbString.

If rOne is a String and rTwo is numeric, rTwo will be coerced to a String, the bytes within that string will be reversed, and whichever argument String is now shorter will be left-padded with zero-value bytes (the strings will be right aligned).

If rOne is numeric and rTwo is a String, rOne will be coerced to a String, the bytes within that string will be reversed, and whichever argument string is now shorter will be left-padded with zero-value bytes (the Strings will be right aligned).

If both rOne and rTwo are numeric, both will be coerced into String values, and rFixUpToType will be set to an appropriately-capable data type, as described in the following table:

               Var2
               Byt Int Lng Sng Dat Cur Dec Dbl
             +--------------------------------
    Var1 Byt | Byt Int Lng Sng Dat Cur Dec Dbl
         Int | Int Int Lng Sng Dat Cur Dec Dbl
         Lng | Lng Lng Lng Sng Dat Cur Dec Dbl
         Sng | Sng Sng Sng Sng Dat Cur Dec Dbl
         Dat | Dat Dat Dat Dat Dat Cur Dec Dbl
         Cur | Cur Cur Cur Cur Cur Cur Dec Dbl
         Dec | Dec Dec Dec Dec Dec Dec Dec Dbl
         Dbl | Dbl Dbl Dbl Dbl Dbl Dbl Dbl Dbl
Abbreviations:
    Byt = Byte
    Int = Integer
    Lng = Long (integer)
    Sng = Single (precision floating point)
    Dat = Date
    Cur = Currency
    Dec = Decimal
    Dbl = Double (precision floating point)
v1.5 Change: This function has been extended to support the new Decimal data type in VB 6.0.

If the fixed-up Strings have different lengths, whichever argument string is now shorter will be right-padded with zero-value bytes so that it is as long as the other string.

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