LIST Data Type

Description

Used to declare a list variable.

Syntax

LIST [ OF data-type ] list-id [= elements]
Variable Description
data-type An identifier specifying the data type you want the elements in the list to have. If omitted, the data type is ANYTYPE.

In addition to ANYTYPE, you can use the following data types: BOOLEAN, BROWSERTYPE, CHAR, DATACLASS, DATATYPE, DATE, DATETIME, DOUBLE, FLOAT, GUITYPE, HANDLE, INT, INTEGER, LONG, NUMBER, REAL, SEMAPHORE, SHORT, STRING, TIME, UNSIGNED CHAR, UNSIGNED INT, UNSIGNED LONG, UNSIGNED SHORT, WINDOW

list-id An identifier that specifies the name of the list.
elements The elements of the list, specified using the list constructor operator.

Notes

Use the LIST and ARRAY compound data types to group together several pieces of data of the same data type.

A list contains elements you can access randomly by referring to them relative to their position in the list. As in an array, all the elements in a list must have the same type. Lists differ from arrays in that you do not need to specify their initial size when you declare them.

List Constructor

To specify the elements of a list, use the list constructor operator. The list constructor has three variants, summarized below:

Format Description Example
{ a , b } The elements of the list, separated by commas and enclosed in braces.
LIST MyList = {"a","b"}
{...} The literal characters {...} followed by indented lines, each containing one element of the list
[-] LIST MyList = {...}
	[ ] "a"
 [ ] "b"
<text>

For lists of string elements only. The literal characters <text> followed by indented lines each containing one element of the list.

Each element is treated as the literal text of a string. Do not use quotes to indicate strings.

4Test interprets indentation levels on the lines as tabs in the string.

[-] LIST MyList = <text>
	[ ] a
	[ ] "b"
	[ ] 	c
Note: In this example, the three elements of the list are the strings "a", ""b"" and "<tab>c".

Referring to List Elements

You refer to specific elements in a list the same way you refer to elements in an array. For example, LIST [2] of the list {"a", "b", "c"} refers to "b". Silk Test Classic raises an exception if you refer to a list item using an index that is out of bounds.

Examples

[ ] // Declare and construct a list
[ ] STRING sSomeString = "hello"
[ ] INTEGER i = 1
[-] LIST OF ANYTYPE NewList = {...}
	[ ] "a" 
	[ ] sSomeString 
	[ ] "cde" 
	[ ] i + 1 
[ ] // Declare an empty list
[ ] LIST OF STRING lsFruit
[ ] // Add to empty list
[-] testcase list_example ()
	[ ] ListAppend (lsFruit, "apples") 
	[ ] ListAppend (lsFruit, "oranges")