ListFindItem Example

InstallShield 2016 » InstallScript Language Reference

Note • To call this function in a Basic MSI setup, you must first create a custom action for the entry-point function, execute the custom action in a sequence or as the result of a dialog's control event, and then build the release.

/*--------------------------------------------------------------*\

*

* InstallShield Example Script

*

* Demonstrates the ListFindItem function.

*

* This script creates a number list and adds three numbers

* to it.  The user is then asked to guess one of the numbers.

* ListFindItem is called to search the list for the number the

* user entered.  A message box is displayed to tell the user

* whether the guess was right or wrong.

*

\*--------------------------------------------------------------*/

 

#define TITLE_TEXT "ListFindItem Example"

 

// Include Ifx.h for built-in InstallScript function prototypes.

#include "Ifx.h"

 

export prototype ExFn_ListFindItem(HWND);

 

function ExFn_ListFindItem(hMSI)

    STRING svItem;

    NUMBER nItem, nResult;

    LIST listID;

begin

 

    // Create a number list.

    listID = ListCreate (NUMBERLIST);

 

    // If an error occurred, report it; then terminate.

    if (listID = LIST_NULL) then

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

        abort;

    endif;

 

    // Add three numbers to the list

    ListAddItem (listID, 1, AFTER);

    ListAddItem (listID, 5, AFTER);

    ListAddItem (listID, 9, AFTER);

 

    // Prompt user for a number.

    if AskText ("Three numbers between 1 and 10 have been added to a list.\n"+

               "Try to guess one of those numbers.", "", svItem) = NEXT then

        // Convert the value from string data to number data.

        if StrToNum (nItem, svItem) < 0 then

            MessageBox ("You did not enter a number: operation canceled.", SEVERE);

        else

            // Make the first list element the current element

            // so ListFindItem searches from the top of the list.

            ListSetIndex (listID, 0);

 

            // Search for the list of numbers.

            nResult = ListFindItem (listID, nItem);

 

            // Display the results of the search.

            if (nResult < 0) then

                MessageBox ("ListFindItem failed.", SEVERE);

            elseif (nResult = END_OF_LIST) then

                SprintfBox (WARNING, TITLE_TEXT, "Sorry, %d is not in the list.", nItem);

            elseif (nResult = 0) then

                SprintfBox (INFORMATION, TITLE_TEXT, "Yes, %d is in the list.", nItem);

            endif;

        endif;

    endif;

 

    // Remove list from memory.

    ListDestroy (listID);

 

end;