Add to Array with list syntax MyArray [= Array(value1, value2, ..., valueN)

I don’t know what to call this syntax for creating an array. What is it if you know?
MyArray [= Array(value1, value2, ..., valueN)
It’s got a similar syntax to a type of If statement.

Is there any specific syntax for adding members to an array?
Does it have to be done in text as in hard code.

Can I have a stored string separated with tabs?

I’m asking because the syntax in the LR uses commas and I don’t know if those are required

If I understand your question…

var arr1() as integer = array( 1, 2, 3 )
var arr2() as string = array( "a", "b", "c" )
var arr3() as variant
arr3.AddRow "a"
arr3.AddRow 2
arr3.AddRow nil
var arr4() as variant  = ParseJSON( "[1, ""a"", false]" )

// Or
Function VarArray(ParamArray arr() As Variant)
  return arr
End Function

var arr5() as variant = VarArray( "a", 2, nil, false )
1 Like

Another variation for readability:

var arr6() as string = array( _
  "a", _
  "b",  _
  "c" _
  )

I think the [= syntax is similar to PHP’s .= syntax which appends to the value. I think OP is looking for a way to do a simplified version of

var arr1() as Integer = Array(1, 2, 3)
arr1.Append(Array(4, 5, 6))

Which, I don’t think is supported in any way through the Xojo syntax. You’d have to iterate the values and append them one by one. A function could be written to do this, but it’s not included in the framework.

Thanks for answering so fast.
I guess the most important question for me is:

Does it have to be a “Comma Delimited” list?

I store my headings in a preferences file with tabs, but I could very easily switch to commas.

Also, if the comma is the only way, then I would make a FeedBack request to add the option of a different delimiter for splitting the string.

If you’re turning a string into an array, you can do so with whatever token you’d like because you have to write the parsing function.

The Array function is not using the list as a string.

1 Like

Sorry. I couldn’t figure out how to do my research.

The syntax comes from the Array Method.
https://documentation.xojo.com/api/language/array.html

It specifically requires;

A comma-delimited list of values that are used to populate result .

This will always be confusing until it is specifically learned.

See. The default delimiter in Split is a blank space or " ".