StrSub Example

InstallShield 2020 ยป 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 StrSub function.

*

* This script gets a date from the user and then calls StrSub

* to extract the four-digit year.  Finally, the year is

* displayed in a message box.

*

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

 

#define TITLE_TEXT "StrSub Example"

 

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

#include "Ifx.h"

 

export prototype ExFn_StrSub(HWND);

 

function ExFn_StrSub(hMSI)

    STRING svYear, svDate, szQuestion, szTitle, szMsg;

    NUMBER nYear;

    BOOL bDateOk;

begin

 

    // Set up message parameter for call to AskText.

    szQuestion = "Please enter the date in this form MM/DD/YYYY:";

 

    repeat

        // Get a date from the user.

        AskText (szQuestion, "09/28/1998", svDate);

        

        // Check the format of the date entered by the user.

        bDateOk = (StrLength(svDate) = 10) &&

                  (svDate[2] = "/") &&

                  (svDate[5] = "/");

        

        // If the date format is incorrect, report an error.

        if !bDateOk then

            MessageBox(svDate + " is not a date in the specified format.", WARNING);

        endif;

    until bDateOk ;

 

    // Retrieve the four-digit year, which starts at byte six.

    if (StrSub (svYear, svDate, 6, 4) < 0) then

        MessageBox ("StrSub failed.", SEVERE);

    endif;

 

    // Validate the year field.

    if StrToNum(nYear, svYear) = 0 then

        // Display the edited string.

        szMsg = "You specified the year %s";

        SprintfBox (INFORMATION, TITLE_TEXT, szMsg, svYear);

    else

        MessageBox(svDate + " is not a date in the specified format.", WARNING);

    endif;

 

end;