Auto

From Xojo Documentation

Data Type


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

Notes

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
Dim num As Auto
num = 42

Dim sum As Integer
sum = num + 10

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

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

Check the type of an Auto variable:

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

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

Compare type of an Auto variable:

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

See Also

Text