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).

As operator

Original typeCan convert to
Any numeric type1Any other numeric type, String, object2
BooleanAny numeric type, String, object
Char, Char arrayString
Any object typeAny data type3
StringAny numeric type, Char, DateTime, object
  1. Int8, UInt8, Int16, UInt16, Int32, UInt32, Int, UInt, Int64, UInt64, Int128, UInt128, Real32, Real64, Real, Real128
  2. Must have a type conversion constructor.
  3. Must have a type conversion method.

In operator

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.