InstallShield 2013
Like InstallScript’s built-in functions, user-defined functions can be designed to return a value to the caller. To return a value from a function, you must include a return statement, followed by the value to be returned, before the function’s end statement. If you do not include a return statement or if you do not specify a value after the keyword return, the value returned by the function is unpredictable. (If the function prototype specifies a return type of void, the function cannot return a value.)
Many programmers use return statements to return error codes that indicate the success or failure of a function call. Most of InstallScript’s built-in functions use a return statement for that purpose. The return statement also is used commonly to create functions that return the result of an operation performed on parameters passed to the function, as in the example below, which returns the area of a rectangle:
function RectangleArea (nLength, nWidth)
INT nVal;
begin
nVal = (nLength * nWidth);
return nVal;
end;
The keyword return can be followed by a constant, a variable, a numeric or string expression, or a function call. In the example below, RectangleArea has been modified to eliminate the assignment statement; the arithmetic expression follows the keyword return:
function RectangleArea (nLength, nWidth)
begin
return (nLength * nWidth);
end;
The value returned by a function can be ignored by the calling program or function, tested in a conditional expression, or assigned to a variable. In the following example, the return value from RectangleArea is assigned to the variable nArea:
nArea = RectangleArea (nLong, nWide);
In the next example, the result of RectangleArea is tested in a conditional expression:
if (RectangleArea(nLong, nWide) > nMaxArea) then
MessageBox("Area exceeds maximum allowed.", INFORMATION);
endif;
To return more than one value or non-numeric values, use the BYREF operator to define parameters that are passed by reference.
See Also
InstallShield Help LibraryJune 2013 |
Copyright Information | Contact Us |