An array is a useful container for storing a sorted series of values while a dictionary is good for storing key-value pairs. It is possible to assign both to a global Newlook variable.
The following information outlines how to set and get Newlook arrays and dictionaries.
For more information on JScript and VBScript arrays, refer to the official Microsoft JScript and VBScript documentation.
To assign values to a Newlook variable array, you will need to use the App.SetValue method.
To assign values to a single dimensional array, you can specify the array index value against each of the values to be assigned.
Example
App.SetValue ("myArray(0)", 1);
App.SetValue ("myArray(1)", "two");
App.SetValue ("myArray(2)", 3.333);
It is also possible to create and initialize arrays in a single SetValue statement, using the following syntax:
Syntax
App.SetValue ("myArray", [ n1, n2, n3, ...]);
Example
App.SetValue ("myArray", [1, "two", 3.333]);
To assign values to a multi-dimensional array, you will need to specify the indices for each element assigned:
Example
App.SetValue ("studentArray(0,0)", "Amy Smith");
App.SetValue ("studentArray(0,1)", "Biology");
App.SetValue ("studentArray(0,2)", 23);
App.SetValue ("studentArray(1,0)", "Joe Blogs");
App.SetValue ("studentArray(1,1)", "Zoology");
App.SetValue ("studentArray(1,2)", 34);
To clear a Newlook array element, set its value to either null or an empty string.
A dictionary consists of items which are stored in an array. Each item is associated with a unique key. The key is used to retrieve an individual item.
To create a Newlook dictionary the SetValue method must be used with the following syntax:
Example
App.SetValue("studentAges", [ {name:"Amy", age: 23}, {name:"Joe", age: 32} ]);
It is also possible to create a user defined type record structure, which allows you to store non-uniform arrays:
Syntax
App.SetValue ("myRecord", { arg1: n1, arg2:n2, arg3:n3, ...});
Example
App.SetValue("course", { name: "Amy", age: 26, majors: [ "Biology" , "Chemistry"]});
To retrieve a single value from a single-dimensional Newlook array, use the GetValue method, specifying the index of the value you wish to retrieve:
Example
vScriptVariable = App.GetValue ("myArray(1)");
vScriptVariable = App.GetValue ("myArray("+ vIndex +")");
The GetValue method is also used to retrieve values from multi-dimensional arrays, but you will need to specify the indices for the value you wish to retrieve:
Example
vScriptVariable = App.GetValue ("studentsArray(1,0)");
vScriptVariable = App.GetValue ("studentsArray("+ vIndex +",0)");
Newlook supports implicit array conversion in JScript:
Example
App.SetValue("myArray", [ 1, "0x0008", { three: 3 } ]);
var myArray = new VBArray(App.GetValue("myArray")).toArray();
var value = myArray[0] + parseInt(myArray[1], 16) * myArray[2].three;
App.MsgBox(value, "My Array Value");
Newlook also support implicit record structure conversion in JScript:
Example
App.SetValue("myRecord", { arg1: "5", arg2: 2, arg3: [ 4 ] });
var myRecord = App.GetValue("myRecord");
var value = new Number(myRecord.arg1) * myRecord.arg2 + new VBArray(myRecord.arg3).toArray()[0];
App.MsgBox(value, "My Record Value")
Values are assigned to an array by specifying the array index value against each one of the values to be assigned.
For a single dimension array:
Example
App.SetValue "testVBArray(0)", "One"
App.SetValue "testVBArray(1)", 2
App.SetValue "testVBArray(2)", 3.333
App.SetValue "testVBArray(3)", #4:44:44 PM#
For a multi-dimensional array:
Example
App.SetValue "studentArray(0,0)", "Amy Smith"
App.SetValue "studentArray(0,1)", 32
App.SetValue "studentArray(1,0)", "Joe Blogs"
App.SetValue "studentArray(1,1)", 28
The only way to clear an array element is by setting its value to an empty string.
For a single dimension arrays:
Example
vScriptVariable = App.GetValue ("arrNames(1)")
vScriptVariable = App.GetValue ("arrNames("& vIndex &")")
For a multi-dimensional array:
Example
vScriptVariable = App.GetValue ("arrStudents(1,1)")
vScriptVariable = App.GetValue ("arrStudents("& vIndex &", 1)")
It is possible to pass a COM array to a VBScript (the Newlook array is automatically converted to a COM array behind the scenes) then access the array's element value.
Working with controls in scripts | Working with variables in scripts
© 2004-2021 looksoftware. All rights reserved.