MoneyWorks Manual
CreateArray ( [key, value, ... ])
Result type: array.
Definition: Without parameters, creates an empty associative array object.
Associative arrays use the syntax arrayname[key], where key can be any text up to 31 characters, an integer, or a date (internally, integers and dates are represented as text formatted so that lexical sort order matches numeric/date sort order). Data values can be any other type.
let myArray = CreateArray() let myArray[0] = "thing" let myArray["mykey"] = myArray[0] let myArray['31/1/12'] = 500
In the current implementation, insertion into an associative array is O(N). Retrieval is O(log N).
Arrays, like Tables, are always passed by reference, so if you assign an array to another variable, or pass it as a parameter to a function, you are not copying the array. If you want to copy an array, you must allocate a new array with CreateArray and explictly copy all of its members.
In MoneyWorks 9 and later, you can provide parameters for initialising the array.
let myArray = CreateArray(0, "thing", "mykey", "thing", '31/1/12', 500) syslog(myarray[0]) syslog(myarray["mykey"]) syslog(myarray['31/1/12'])
This is particularly useful for passing to functions that require an array parameter. E.g. BeginXMLElement(xml, "import", CreateArray("table", "transaction"))
Availability: available within MWScript handlers.
See Also:
CountElements: Get the size of an associative array
DeleteElement: Remove a key from an associative array
ElementExists: Check if a key exists in an associative array
ParamsFromArray: Expand array values to a variable parameter list