Saturday head scratcher

This works

Dim i As Integer i = Integer(i)

but this doesn’t

Dim s As String s = String(s)

Any ideas why?

While strings look like basic types like integers in fact they are a reference type
That probably plays into it
I would not be surprised if there’s no way to actually use String(var) as a cast because of this

Maybe it’s because Integer is an alias in Xojo for the appropriate int on the platform you are building for (Int32 or Int64)? So under the hood, it can actually try to do something, which it can’t do for the String as it’s still a String? Otherwise, no clue.

And the error info is not helpful

[quote]Window1.PushButton1.Action, line 2
Type mismatch error. Expected String, but got String
s = String(s)[/quote]

Edit: but I don’t know what Integer(i) or String(s) do.

Integer(thing) takes a number (thing) and gives you the integer part

There is no ‘convert to string’ option called String
Its Format() or str()

Humm. No. It casts an “Integer” from “another compatible integer type” as an Integer. E.g. Enums.
An Enum, in it’s internals, is an “integer”, but it can’t be used in math, but… if you cast it’s “value” as an Integer first, you can.

[code]

Dim i As integer = Integer(ReportPicture.PictureAlignment.BottomLeft) // You’ll get an int 3
Dim j As integer = ReportPicture.PictureAlignment.Center // compiler error. Integer <> Enum.[/code]