Array vis a vis Text and String

I notice that if a I Dim a String Array and load it with a mix of Text and String members, the WebListBox.AddRow method (which currently only accepts String rows) will work fine because that Array will be seen as a String Array, even though some of its members are Text. But if all the members of that Array are Text, it will fail because that array is now seen as a Text Array.

Is this way of working with Arrays working as designed? That is, Xojo sees an Array that is a mix of Text and String members as a String Array, at least in terms of loading that Array of rows into a WebListBox.

Should I worry that a future version of Xojo might see that Array that contains a mix of Text and String members as improperly formed?

Text auto converts to string. You should be able to affect any Text element to addrow without any special manipulation.

This is not my experience in this situation.

For instance, this fails to compile:

Dim row() As String Dim s As Text = "This is text." Dim t As Text = "This is more text." row = Array(s, t)
The latter yields this

Type mismatch error. Expected String(), but got Text() row = Array(s, t)

Of course, this will compile:

Dim row() As Text Dim s As Text = "This is text." Dim t As Text = "This is more text." row = Array(s, t)

but this will not:

Dim row() As Text Dim s As Text = "This is text." Dim t As Text = "This is more text." row = Array(s, t) ListBox1.AddRow(row)

The latter yields

There is more than one item with this name and it's not clear to which this refers. ListBox1.AddRow(row)

But if I mix String and Text in the Array, everything works fine. This compiles and works:

Dim row() As String Dim arr() As String Dim s As String = "This is a string." Dim t As Text = "This is text." arr = Array(s, t) row = arr ListBox1.AddRow(row)

AddRow (single item) expect a String, when you use a text it will auto converted to String.

AddRow (array) expect String() that is not the same as Text() a your first example shows.

[quote=370035:@Antonio Rinaldi]AddRow (single item) expect a String, when you use a text it will auto converted to String.

AddRow (array) expect String() that is not the same as Text() a your first example shows.[/quote]
What I don’t understand is why does this work

Dim row() As String Dim s As String = "This is a string." Dim t As Text = "This is text." row = Array(s, t) ListBox1.AddRow(row)

when this does not

Dim row() As String Dim s As Text = "This is text." Dim t As Text = "This is more text." row = Array(s, t) ListBox1.AddRow(row)

What is the error you get for the second code you posted ?

Array( t1, t2) … just to be clear in your notation… create a new array and it’s build on text and text so it’s text()

and again text() is not string()

[quote=370039:@Michel Bujardet]Dim row() As String
Dim s As Text = “This is text.”
Dim t As Text = “This is more text.”
row = Array(s, t)
ListBox1.AddRow(row)[/quote]

WebPage1.Button3.Action, line 4
Type mismatch error. Expected String(), but got Text()
row = Array(s, t)

[quote=370040:@Antonio Rinaldi]Array( t1, t2) … just to be clear in your notation… create a new array and it’s build on text and text so it’s text()

and again text() is not string()[/quote]

So, if the array is built on a mixture of String members and Text members, then it will be considered String. If it is built on only Text members, it will be built as Text. Eventhough I declared the array as String.

In your first example, String is the first element. That matches type of the row() array. Any following text values auto-convert to String.

In your second example, Text is the first element. That does not match the type of the row() array so you get a Type Mismatch error.

Use CType to convert the Text to a String so that the Arrays match:

row = Array(CType(s, String), t)