Chapter 11
Corel® PerfectScript Programming Commands
Corel® PerfectScript Programming Commands
Three new macro commands have been added: MacroCompile, MacroIsCompiled, and MacroPlay. See online Help for information about these commands. Also, the following commands have been changed: DialogAddControl, DialogDelete, FileFind, FileNameDialog, GetFileAttributes, MacroInfo, OLEAutomation, and SetFileAttributes. See online Help for information about these commands.
|
Else |
| Purpose | All statements between Else and Endif are executed when the If expression is False. See If. |
| Syntax | Else |
|
ElseIfPlatform |
| Purpose | Works with IfPlatform and EndIfPlatform statements, similar to the Else statement in an If-Else-Endif control statement except that a new platform ID may be specified. | |||
| Syntax |
|
|||
| Parameters |
|
|
EndApp |
| Purpose |
Identify, for the compiler, an application that is no longer used in a macro (see Application). EndApp is a non-executable statement that can occur anywhere in a macro. After EndApp, a product command to the application specified by EndApp creates a compile-time syntax error. |
|||
| Examples | Appendix A: 8058 | |||
| Syntax |
|
|||
| Parameters |
|
|
EndFor |
| Purpose | Close a For control loop. See For, ForEach, ForNext. |
| Syntax | EndFor |
|
EndFunc |
| Purpose | Close a Function statement (synonym for EndFunction). See Function. |
| Syntax | EndFunc |
|
EndFunction |
| Purpose | Close a Function statement (synonym for EndFunc). See Function. |
| Syntax | EndFunction |
|
EndIf |
| Purpose | Close an If control statement. See If. |
| Syntax | EndIf |
|
EndIfPlatform |
| Purpose |
Close an IfPlatform conditional compile statement. See IfPlatform. The parameter is optional and ignored. Its only purpose is to document what it goes with. |
||
| Syntax |
|
|
EndProc |
| Purpose | Close a Procedure statement (synonym for EndProcedure). See Procedure. |
| Syntax | EndProc |
|
EndProcedure |
| Purpose | Close a Procedure statement (synonym for EndProc). See Procedure. |
| Syntax | EndProcedure |
|
EndPrompt |
| Purpose | Terminate the current Prompt. See Prompt. |
| Syntax | EndPrompt |
|
EndSwitch |
| Purpose | Close a Switch control statement. See Switch. |
| Syntax | EndSwitch |
|
EndWhile |
| Purpose | Close a While control loop. See While. |
| Syntax | EndWhile |
|
EndWith |
| Purpose | Close a With statement. See With. |
| Syntax | EndWith |
|
EnvVariableGet |
| Purpose | Return the value of an environment variable. | ||||||||
| Return Value | Environment variable value. | ||||||||
| Syntax |
|
||||||||
| Parameters |
|
|
EnvVariableSet |
| Purpose | Set the value of an environment variable, or delete it. | |||||||||||
| Syntax |
|
|||||||||||
| Parameters |
|
|
Error |
| Purpose | Determine how a macro responds to an Error condition. Create an Error condition with Assert(ErrorCondition!). | |||||||||
| Examples | Appendix A: 8020 | |||||||||
| Return Value |
|
|||||||||
| Syntax |
|
|||||||||
| Parameters |
|
|
ErrorNumber |
| Purpose | Return the error value of a Cancel, Error, Not Found, or user-defined condition. | ||||||||||
|
Notes |
ErrorNumber is a macro system variable that returns an enumeration, which can be referred to by name. The enumerations have the same numeric values as in previous versions. The value of ErrorNumber is cleared before every command. After the command is excuted, ErrorNumber returns a value that indicates if an error occured. If a handler condition is disabled, the macro continues when the specified condition occurs. You can test ErrorNumber manually for ErrorNumber.Success!. Commands that do not reset Error Number are MacroInfo(ErrorNumber!) calls, ErrorNumber itself, and compound statements, such as If- Endif, Switch-EndSwitch, Repeat-Until, While- EndWhile, For-EndFor, and so on. Copy the value returned by ErrorNumber into a variable if the value is needed after executing other macro commands, such as PROMPT, which reset ErrorNumber. |
||||||||||
| Return Value |
|
||||||||||
| Syntax | enumeration := ErrorNumber |
|
Exists |
| Purpose |
Determine if a variable exists. To exist, a variable must be declared and initialized. Given that variable w is declared and not initialized, and that Local x is initialized to 5, Global y to 10, and Persist z to 15, the following statements are valid: vNoInit := Exists(w) Result: vNoInit equals Exists.NotFound! vLocal := Exists(x) Result: vLocal equals Exists.Local! vGlobal := Exists(y) Result: vGlobal equals Exists.Global! vPersist := Exists(z) Result: vPersist = Exists.Persistent! If(Exists(vLocal)) Beep EndIf Explanation: Computer beeps because Exists returns a value other than Exists.NotFound!. If(Exists(vLocal) = Exists.Persistent!) Beep EndIf Explanation: The computer does not beep because Exists returns Exists.Local!. (vLocal is a Local variable, not a Persist variable.) |
|||||||||||||||
| Examples | Appendix A: 8022 | |||||||||||||||
| Return Value | If Pool is left off, the values are: | |||||||||||||||
|
||||||||||||||||
| Syntax |
|
|||||||||||||||
| Parameters |
|
|
ExitHandlerState |
| Purpose |
Determine how a macro responds to an Exit condition. Create an Exit condition with Assert(ExitCondition!). Unlike Error, Cancel, and NotFound, ExitHandlerState does not prevent or enable a condition from occurring. It enables or disables calling the exit handler when an exit condition occurs. |
|||||||||
| Examples | Appendix A: 8022 | |||||||||
| Return Value |
|
|||||||||
| Syntax |
|
|||||||||
| Parameters |
|
|
ExponentPart |
| Purpose |
Return the exponent portion of a numeric value. For example, the exponent of 3.2e18 is 18. |
|||
| Return Value | Exponent portion of a numeric value. | |||
| Syntax |
|
|||
| Parameters |
|
|
Factorial |
| Purpose | Return the Nth factorial, which is the product of all numbers in a series (1, 1, 2, 5, 24,...) less than or equal to a specified value. | |||
| Return Value | Nth factorial. | |||
| Syntax |
|
|||
| Parameters |
|
|
False |
| Purpose |
The constant boolean value FALSE. |
| Syntax | boolean := False |
|
Fibonacci |
| Purpose | Return the Nth term in a Fibonacci sequence (0, 1, 1, 2, 3,...). The Fibonacci is the sum of the preceding two terms in the series. | |||
| Return Value | Nth term in a Fibonacci sequence. | |||
| Syntax |
|
|||
| Parameters |
|
|
FileConvert |
| Purpose |
Converts a file of one type to a file of another type. The available file types depends on the converters installed by the user. Not all conversions are available on all systems. A file can only be converted to a similar file type (documents to documents, graphics to graphics, and so on). |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Return Value | The common return values follow. Any value not equal to Success! is an error. Other error values are returned as numeric values. |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Syntax |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Parameters |
|
|
FileConvertError |
| Purpose | Returns the name of a file conversion error. | ||||||||||||||||||||||||
| Return Value | Printable name of the error returned by the FileType command. | ||||||||||||||||||||||||
| Syntax |
|
||||||||||||||||||||||||
| Parameters |
|
|
FileError |
| Purpose | Return the error associated with the last file command. |
| Examples | Appendix A: 8090 |
| Return Value | A number greater than 0 (last file error), -1 (unknown error), or 0 (no error). Error numbers have loword and hiword values. The loword contains an error code generated by Corel WordPerfect's I/O routines, described in the Corel WordPerfect for Windows SDK (WError.H file). The hiword contains a Windows specific error value, described in the Microsoft Windows SDK. |
| Syntax | numeric := FileError () |
|
FileFind |
| Purpose | Find a file that matches user-defined search criteria (filename and DOS attributes). | ||||||||||||||||||||||||
| Examples | Appendix A: 8090 | ||||||||||||||||||||||||
| Return Value |
A filename, or an empty filename if no match is found. |
||||||||||||||||||||||||
| Syntax |
|
||||||||||||||||||||||||
| Parameters |
|
|
FileIsEOF |
| Purpose |
Return True if the insertion point is at the end of a file, False if not. The access mode must be Read! (see OpenFile). |
|||
| Examples | Appendix A: 8088 | |||
| Return Value | True/False. | |||
| Syntax |
|
|||
| Parameters |
|
|
FileNameDialog |
| Purpose | Display the Open or Save As dialog. | |||||||||||||||||||||||||||||||||
| Return Value | The name of the file to open or save, or "" if Cancel is pressed. | |||||||||||||||||||||||||||||||||
| Syntax |
|
|||||||||||||||||||||||||||||||||
| Parameters |
|
|
FilePosition |
| Purpose |
Return the current marker position or set a new position. A user can pre-allocate file size by setting the position marker past the end-of-file marker. |
|||||||||||||||
| Examples | Appendix A: 8088 | |||||||||||||||
| Return Value | The position of the old position marker, or a negative number if an error occurs. | |||||||||||||||
| Syntax |
|
|||||||||||||||
| Parameters |
|
|
FileRead |
| Purpose | Read text data from an open file. | ||||||
| Examples | Appendix A: 8088 | ||||||
| Return Value | The number of bytes read, or a negative number if an error occurs. | ||||||
| Syntax |
|
||||||
| Parameters |
|
|
FileSize |
| Purpose | Return a file's size in bytes. | |||
| Examples | Appendix A: 8088 | |||
| Return Value |
The file size in bytes, or a negative number if an error occurs. |
|||
| Syntax |
|
|||
| Parameters |
|
|
FileTruncate |
| Purpose | Remove all text data after the position marker (see FilePosition). | |||
| Examples | Appendix A: 8089 | |||
| Return Value | The truncated file size (bytes) if successful, or a negative number if an error occurs. | |||
| Syntax |
|
|||
| Parameters |
|
|
FileType |
| Purpose | Return a file's file type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Return Value | Detected file type (get errors from the FileError command). The more common file types are listed below. Since over 200 file types are recognized, those not listed are returned as numeric values. The values returned may change in future releases of PerfectScript. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Syntax |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Parameters |
|
|
FileTypeExtension |
| Purpose | Return the default filename extension of a file type returned by the FileType command. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Return Value | The default filename extension of FileType (usually two or three characters). If FileType does not have an extension, or if you specify an invalid file type, an empty string is returned. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Syntax |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Parameters |
|
|
FileTypeList |
| Purpose | Return an array (list) of detected file types. | ||||||||||||
| Return Value | An array of file types (the same types returned by the FileType command). Associated names are obtained by passing the file types to the FileTypeName command. | ||||||||||||
| Syntax |
|
||||||||||||
| Parameters |
|
|
FileTypeName |
| Purpose | Returns the name of a file type. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Return Value | Printable name of the file type returned by the FileType command. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Syntax |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Parameters |
|
|
FileWrite |
| Purpose | Write text data to a file. | ||||||||||||||||||||
| Examples | Appendix A: 8088 | ||||||||||||||||||||
| Return Value | The number of bytes written, or a negative number if an error occurs. | ||||||||||||||||||||
| Syntax |
|
||||||||||||||||||||
| Parameters |
|
|
Floor |
| Purpose | Return the largest integer that is less than or equal to a specified value (the floor of a number). | |||
| Return Value | Integer. | |||
| Syntax |
|
|||
| Parameters |
|
|
For |
| Purpose |
A control statement (loop) that executes a specified number of times (see Loop Statements in Chapter 5: Conditional, Loop, and Calling Statements). The loop executes only if TerminateExp is true, and continues to execute until ControlVariable's value makes TerminateExp false. EndFor closes a For statement. The general form of a For statement is:
For example, the following statement initializes vTest to one, repeats the statement block while vTest is less than ten, and increments vTest by two after each loop.
|
||||||||||||
| Examples | Appendix A: 8022 | ||||||||||||
| Syntax |
|
||||||||||||
|
|||||||||||||
| Parameters |
|
|
ForEach |
| Purpose |
A loop statement that executes a number of times equal to the number of specified expressions (see Loop Statements in Chapter 5: Conditional, Loop, and Calling Statements). ControlVariable is assigned the first value before the first loop; the second value before the second loop; the third value before the third loop; and so forth. The statement block uses the value of ControlVariable to direct macro execution. EndFor closes a ForEach statement. The general form of a ForEach statement is:
For example, the following statement repeats three times. The variable vTest is initialized to "Apples" before the first loop, to "Oranges" before the second, and to "Bananas" before the third.
|
||||||
| Examples | Appendix A: 8003 | ||||||
| Syntax |
|
||||||
|
|||||||
| Parameters |
|
|
ForNext |
| Purpose |
A loop statement that executes a specified number of times (seeLoop Statements in Chapter 5: Conditional, Loop, and Calling Statements). The loop executes if ControlVariable is less than or equal to FinalValue, and executes until ControlVariable is greater than FinalValue. If you use a negative value in IncrementValue, the loop executes until ControlVariable is less than FinalValue. EndFor closes a ForNext statement. The general form of a ForNext statement is,
The following statement initializes vTest to one, repeats the statement block while vTest is less than or equal to five, and increments vTest by two after each loop.
|
||||||||||||
| Examples | Appendix A: 8001 | ||||||||||||
| Syntax |
|
||||||||||||
|
|||||||||||||
| Parameters |
|
|
Fraction |
| Purpose | Return the fractional portion of a real number. | |||
| Examples | Appendix A: 8023 | |||
| Return Value |
A fraction. vFraction := Fraction(1.5) Result: vFraction equals 0.5 vResult := Fraction(1.77 * 2) Result: vResult = 0.54 |
|||
| Syntax |
|
|||
| Parameters |
|
|
FractionalPart |
| Purpose |
Return the fractional portion of a numeric value. vFrac := FractionalPart (3.2) Result: vFrac = 0.2 |
|||
| Return Value | Fractional portion of a numeric value. | |||
| Syntax |
|
|||
| Parameters |
|
|
FractionStr |
| Purpose |
Return a fraction string representing a value. vStr := FractionStr (4.5; 0; MixedFraction!) Result: vStr = "4 1/2" vStr := FractionStr (4.5; 8; MixedFraction!) Result: vStr = "4 4/8" |
|||||||||||||||
| Return Value | Fraction string. | |||||||||||||||
| Syntax |
|
|||||||||||||||
| Parameters |
|
|
Function |
| Purpose |
Identify a macro subroutine that can receive one or more values from a calling statement (see Calling Statements in Chapter 5: Conditional, Loop, and Calling Statements). Function also returns a value to the calling statement (caller). Functions contain one or more statements that execute when the function is called. Unlike Label statements, functions do not execute unless called. A calling statement consists of the function's name, and can have one or more parameters that pass values to the function. Return, EndFunc, or EndFunction direct macro execution to the statement that follows the function's caller. Return also returns the result of a function operation, or 0 if no result is specified. For example,
assigns the value 10 to variable x. Add is the name of the function, and y contains a value to pass. Variable z has no value until the function is called, when the value of z is function statement assigns 10 to variable z. The next statement returns the value of z to the calling statement, which is then assigned to variable x. If the function did not contain a Return statement, or if Return did not return a value, x would be equal to 0. |
||||
|
Address Mode |
In the above example, the value of y does not change. The function returns the value of z in variable x. To change the value of a variable passed to a function, precede the calling statement parameter and its corresponding function parameter with an ampersand (&). For example,
assigns the value 10 to both x and y. The ampersand before variable x means the variable's address (location in memory) is passed to the function, not the variable's value. Changes made at the address of x are made to the contents of x. |
||||
|
Arrays |
You pass arrays to functions the same way you pass variables. If you are passing the entire array, every array element must be assigned a value. If not, a run-time error identifies a reference to the undefined element. For example,
In the previous example, if you precede the calling statement parameter
and the corresponding function parameter with an ampersand (&), 100 is
returned in w[10]. No run-time error occurs. You are passing the address
of array w[ ], not its value. The value is assigned inside the function
(see Address Mode above). The two statements look like this:
Function Test(&z[ ])
and y[ ] = Test(&w[ ]) Pass the value of an array element, the same way you pass a variable. For example,
The value of y equals 10. The value of w[1] equals 1. If you precede the calling statement parameter and the corresponding function parameter with an ampersand (&), the value of y equals 10 and the value of w[1] equals 10. Passing the address of w[1] causes its value to change inside the function. The two statements look like this: Function Test(&z) and y = Test(&w[1]) The general form of a Function statement is:
The syntax accepts EndFunc or EndFunction. |
||||
| Examples | Appendix A: 8024 | ||||
| Syntax |
|
||||
|
|||||
| Parameters |
|