Implicit and Explicit Conversions
An implicit conversion is done automatically by the compiler. No special syntax is necessary. In the example below, ViviFire automatically changes the value of k to a floating-point value, then assigns that to q.
Dim k As Int Dim q As Real ' Int widens to Real k = 321 q = k
An explicit conversion uses a type conversion operator. ViviFire supplies two such operators, As and In, which coerce an expression to the necessary data type.
The example below continues from the example before. The value of q is converted to an Int, then assigned to k.
' q had been assigned the value 321. q = Math.Sqrt(q) k = q As Int ' k now has the value 18 (rounded square root of 321).
|Original type||Can convert to|
|Any numeric type1||Any other numeric type, String, object2|
|Boolean||Any numeric type, String, object|
|Char, Char array||String|
|Any object type||Any data type3|
|String||Any numeric type, Char, DateTime, object|
- Int8, UInt8, Int16, UInt16, Int32, UInt32, Int, UInt, Int64, UInt64, Int128, UInt128, Real32, Real64, Real, Real128
- Must have a type conversion constructor.
- Must have a type conversion method.
The In operator can convert a numeric expression to a unit of measure. If the expression is already a unit of measure, the In operator can convert it to a compatible unit. All units of measure are stored as floating-point types.