From Xojo Documentation

Data Type

The Auto type can store and retrieve any type value, but cannot convert to other types.


Once a value is placed into an Auto variable, it is treated as if it is that type of the value. For example, if you assign an Integer to an Auto variable, you can not later use it as a Text. You'll have to first assign it to an Integer and then convert it to a Text using intVal.ToText. You can use Introspection to check the type of the value contained in an Auto variable as shown in the sample code below. You can assign a value of a different type to an Auto that already had a value.

Sample Code

Some Auto examples:

// Add an Auto containing an integer
Var num As Auto
num = 42

Var sum As Integer
sum = num + 10

// Display an Auto containing an integer
Var numInt As Integer = num
Var output As Text
output = numInt.ToText ' output contains "42"

// Convert an Auto containing a Double to Text
Var num As Auto = 5.5
Var t As Text = CType(num, Double).ToText

Check the type of an Auto variable:

Var autoVar As Auto = 42
Var info As Xojo.Introspection.TypeInfo
info = Xojo.Introspection.GetType(autoVar)

Label1.Text = "Type: " + info.Name // Displays Int32

Compare type of an Auto variable:

Var a As Auto
Var t As Text = "Hello"
a = t
If Xojo.Introspection.GetType(a) = GetTypeInfo(Text) Then
// It's text
End If

See Also