Finding a Particular Element in a List

InstallShield 2025

You can traverse lists non-incrementally. Call the ListFindString function or the ListFindItem function when you want to search for a specific string or number element in a list. These two functions begin their search at the current element and continue forward through the list from that point.

To start a search from the beginning of a list, call the ListGetFirstString or the ListGetFirstItem function before calling the ListFindString or the ListFindItem function.

When the ListFindString or the ListFindItem function finds the specified string or number, it becomes the current element in the list.

In the script fragment below, a number list is created, and the number 1 (in nItem) is added as the first element. Then, ListFindItem searches the list for the number 1, and deletes it, if found. Finally, the list is destroyed.

listID = ListCreate (NUMBERLIST);

 

if (listID = LIST_NULL) then

    MessageBox ("Unable to create list.", SEVERE);

    abort;

endif;

 

nItem = 1;

ListAddItem (listID, nItem, AFTER);

 

if (ListFindItem (listID, nItem) = 0) then

     ListDeleteItem (listID);

endif;

 

ListDestroy (listID);

Note:The ListFindString and ListFindItem functions look for only the first instance of the specified string or number at or after the current element.

See Also