Implicit and Explicit Conversions

An implicit conversion is done automatically by the compiler. No special syntax is necessary. In the example that follows, 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 an operator to change a data type to a different one. 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 changed to Int, then assigned to k.

' q had been assigned the value 321.
q = Math.Sqrt(q)
k = q As Int
' k has the value 18 (rounded square root of 321).

As operator

Initial type Can change to
A numeric type1 All numeric types, String, object2
Boolean All numeric types, String, object
Char, array of Char String
An object type All data types3
String All numeric types, 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 operator In can change a numeric expression to a unit of measure. If the expression is a unit of measure, it can change it to a different unit from the same base unit. All units of measure are stored as floating-point types.