How the CreateArray function works - Forum

Forum Navigation
You need to log in to create posts and topics.

How the CreateArray function works

Hi @luishp,
if I create an array using this code

setvar [a] "x"
setvar [b] "y"
setvar [c] "z"

CreateArray [myArray] "[a],[b],[c]"

jsalert [myArray]

what I get is an array where the elements are "[a]", "[b]" and "[c]" and not as I expected "x","y" and "z".
Is this an intended behavior or an error in the CreateArray function?

One way to get the desired result is to create a type string
setvar [string] "[a],[b],[c]" and use
strParse "[string]" "," [myArray] or create an empty array and use arrayadditem with all elements.

Greetings
Rocco

Hi @roccocogliano, CreateArray was one of the first commands to be included with the old NeoAppBuilder (before it was renamed to VisualNEO Web). It is an easy way to create an Array with values on design time. It's not designed to to store values generated at run time.
As you say, there are other options:

SetVar [a] "x"
SetVar [b] "y"
SetVar [c] "z"
CreateEmptyArray [myArray]
ArrayAddItem [myArray] [a]
ArrayAddItem [myArray] [b]
ArrayAddItem [myArray] [c]

Regards.

roccocogliano has reacted to this post.
roccocogliano

ok @luishp

thanks a lot