Skip to main content
Previous sectionNext section

ListExists

Indicates whether an element is present in the list and has a value.

Synopsis

ListExists(list,position)

Arguments

list An expression that evaluates to a valid list. A Caché list must be created using ListBuild or ListFromString, or extracted from another list using List.
position An integer specifying a position in list (counting from 1).

Description

The ListExists function returns a value of 1 if the element at the indicated position in the list exists and has a data value. Otherwise ListExists returns zero.

Examples

The following example demonstrates the ListExists function. It defines a six-element list, in which the third and fourth elements do not have a defined value:

Erase Y      ' Y is now undefined
myList = ListBuild("Red","Blue",,Y,"Yellow","")
Println ListExists(myList,0)  ' 0: positions are numbered from 1
Println ListExists(myList,1)  ' 1: "Red"
Println ListExists(myList,2)  ' 1: "Blue"
Println ListExists(myList,3)  ' 0: missing element
Println ListExists(myList,4)  ' 0: undefined element
Println ListExists(myList,5)  ' 1: "Yellow"
Println ListExists(myList,6)  ' 1: empty string OK
Println ListExists(myList,7)  ' 0: beyond end of list
Println ListExists(myList,-1) ' 1: last element in list
Copy code to clipboard

See Also