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.
|
Beep |
| Purpose |
Cause a computer speaker or installed sound board to beep. Beep is commonly used with warning messages, or to signal when a macro pauses or finishes a task. |
|||||||||||||||||||||
| Syntax |
|
|||||||||||||||||||||
| Parameters |
|
|
BIFFilePath |
| Purpose |
Retrieve the path and filename of a 16-bit BIF (Binary Initialization File). This command is provided for backward compatibility only. Settings are now located in the Windows Registry (see the Registry commands). |
|||||||||
| Syntax |
|
|||||||||
| Return Value |
The BIF path and filename. |
|||||||||
| Parameters |
|
|
BIFInfo |
| Purpose |
Retrieve information from a BIF (Binary Initialization File). This command is provided for backward compatibility only. Settings are now located in the Windows Registry (see the Registry commands). |
||||||||||||||||||||||||||||||||||||||||||
| Syntax |
|
||||||||||||||||||||||||||||||||||||||||||
| Return Value | The status of the BIF call is returned in a variable. As a function, you can use BIFInfo in an If statement. The values are: | ||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
| Parameters |
|
||||||||||||||||||||||||||||||||||||||||||
| Notes |
No data is returned unless you specify a variable in at least one of
the following five parameters:
DateTime, ItemFlags, ItemLength, ItemType, UseCount |
|
BIFRead |
| Purpose |
Read a BIF (Binary Initialization File), and return Group, Section, or Item names, or item value. This command is provided for backward compatibility only. Settings are now located in the Windows Registry (see the Registry commands). |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Notes |
Group, the highest BIF level. Section, the next BIF level after Group, is associated with Group subdivisions. Item, the lowest BIF level, is associated with a Section entry. Items contain values. Group, Section, and Item names are subject to change. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Return Value |
The status of a BIF call is returned in a variable. As a function, you can use BIFRead in an If statement. Any value greater than or equal to Success! is successful. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Syntax |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Parameters |
|
|
BIFWrite |
| Purpose |
Write data to a BIF (Binary Initialization File), or delete a group, section, or item from a BIF. This command is provided for backward compatibility only. Settings are now located in the Windows Registry (see the Registry commands). |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Notes |
See BIFRead for a description of BIF Groups, Sections, Items, and Values. To write data to a BIF, you must use the Group, Section, Item, and Value parameters. If you do not specify a value for each parameter, you will delete a level or item from the BIF. See the parameter descriptions below. BIFWrite calls to the public and private BIF fail if a Corel WordPerfect Suite application is running. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Return Value | The status of a BIF call is returned in this variable. As a function, you can use BIFRead in an If statement. Any value greater than or equal to Success! is successful. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Syntax |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Parameters |
|
|
BinaryPack |
| Purpose | Pack data into a raw binary data form. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Return Value | Raw binary data returned from BinaryPack. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Syntax |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Parameters |
|
|
BinaryUnPack |
| Purpose |
Unpack data from a raw binary data form. |
|||||||||||||||||||||||||||||||||||||||||||||
| Return Value |
Unpacked data returned by BinaryUnPack. |
|||||||||||||||||||||||||||||||||||||||||||||
| Syntax |
|
|||||||||||||||||||||||||||||||||||||||||||||
| Parameters |
|
|
Break |
| Purpose |
End a loop, and direct macro execution to the first statement after the ending loop statement (seeLoop Statements in Chapter 5: Conditional, Loop, and Calling Statements). In a Switch statement, Break directs macro execution to the first statement after EndSwitch. Break bypasses the normal test expression of a loop or conditional statement. Statements after Break are ignored. |
| Examples | Appendix A: 8022 |
| Syntax | Break |
|
Call |
| Purpose |
Call macro code associated with a Label, Procedure, or Function (see Subroutines in Chapter 5: Conditional, Loop, and Calling Statements); it can pass one or more values to a Procedure or Function. A Return statement in a Label, Procedure, or Function directs macro execution to the statement that follows the call of the Label. |
|||
| Examples | Appendix A: 8005 | |||
| Syntax |
|
|||
| Parameters |
|
|
Call |
| Purpose |
Call macro code associated with a Label, Procedure, or Function (see Subroutines in Chapter 5: Conditional, Loop, and Calling Statements); it can pass one or more values to a Procedure or Function. A Return statement in a Label, Procedure, or Function directs macro execution to the statement that follows the Label's caller. |
|||
| Syntax |
|
|||
| Parameters |
|
|
CallbackResume |
| Purpose | Resume macro execution paused by CallbackWait. The macro continues to the next command after CallbackWait. |
| Examples | Appendix A: 8098 |
| Syntax | CallbackResume |
|
CallbackWait |
| Purpose |
Replace the loop statement after DialogShow, pausing the macro to allow the callback to be executed. Use this command with CallbackResume. CallbackWait and CallbackResume are easier to use and more efficient than loops. |
| Examples |
Appendix A: 8098
|
| Syntax | CallbackWait |
|
Cancel |
| Purpose | Determine how a macro responds to a Cancel condition. Create a Cancel condition by pressing Esc, or with Assert(CancelCondition!). | |||||||||
| Examples | Appendix A: 8005 | |||||||||
| Return Value |
|
|||||||||
| Syntax |
|
|||||||||
| Parameters |
|
|
Case |
| Purpose |
A conditional statement that tests for matching expressions. If a match is found, a Label is called. See Conditional Statements in Chapter 5: Conditional, Loop, and Calling Statements. Case compares <Test> to a set of <Cases> (values). If the first comparison is true (if <Test> and <Case> match), the Label following <Case> is called. If the comparison is false, the next <Case> is evaluated and so forth. If no comparison is true, DefaultLabel is called. |
||||||||||||
| Examples | Appendix A: 8011 | ||||||||||||
| Syntax |
|
||||||||||||
| Parameters |
|
|
Case Call |
| Purpose |
A conditional statement that tests for matching expressions. If a match is found, a Label is called. See Conditional Statements in Chapter 5: Conditional, Loop, and Calling Statements. Case Call compares <Test> to a set of <Cases> (values). If the first comparison is true (if <Test> and <Case> match), the Label following <Case> is executed. If the comparison is false, the next <Case> is evaluated and so forth. If no comparison is true, DefaultLabel is called. Case is different from Case Call, in that a Return statement after Label directs macro execution to the statement that follows Case Call. |
||||||||||||
| Examples | Appendix A: 8007 | ||||||||||||
| Syntax |
|
||||||||||||
| Parameters |
|
|
CaseOf |
| Purpose | Identify the code to execute when a CaseOf <Selector> matches the control expression in a Switch statement. Parentheses around Selector are optional. See Switch. | ||
| Syntax |
|
|
Ceiling |
| Purpose |
Get the smallest integer greater than or equal to a specified value (the ceiling of a number). vInt := Ceiling (15.4) Result: vInt = 16 |
|||
| Return Value | Integer. | |||
| Syntax |
|
|||
| Parameters |
|
|
Chain |
| Purpose |
Call (start) another macro when the parent macro ends. Corel PerfectScript automatically compiles uncompiled Chain macros. Macro execution stops if the macro will not compile. A Chain macro does not return to its caller (see Run). Although Chain can occur anywhere in a macro, the Chain macro does not execute until the current macro ends. If the current macro contains more than one Chain command, only the macro file in the last Chain command is executed when the current macro ends. You can cancel Chain (so the macro is not executed) with a Quit statement. For example,
Explanation: If <Test> equals 1, 2, or 3, the corresponding macro plays when the parent macro ends. If <Test> equals 4, the DoSomethingElse subroutine is called and Test4.wcm plays when the parent macro ends. If <Test> does not equal 1, 2, 3, or 4, the macro quits and a Chain statement does not execute. |
||||||
| Examples | Appendix A: 8009 | ||||||
| Syntax |
|
||||||
| Parameters |
|
|
CharLen |
| Purpose | Return the number of characters in a string, including codes. The string can be a variable, constant, character string, or result of an expression. | |||
| Examples | Appendix A: 8012 | |||
| Return Value | The number of characters, including codes, in a string. | |||
| Syntax |
|
|||
| Parameters |
|
|
CharPos |
| Purpose | Return the beginning character position of a substring in a string. | |||||||||
| Return Value | The beginning character position of a substring, or 0 if a substring is not found. | |||||||||
| Examples |
Appendix A: 8013
vPos := CharPos("WordPerfect"; "Perfect") Result: vPos = 5 vPos := CharPos("WordPerfect"; "Scott") Result: vPos = 0 vPos := CharPos("Corel WordPerfect"; "or"; 7) Result: vPos = 8 Explanation: Search begins at character position 7, bypassing the first occurrence of the substring. |
|||||||||
| Syntax |
|
|||||||||
| Parameters |
|
|
CloseFile |
| Purpose | Close one file or all files. Close file(s) when they are no longer needed, or system resources will be lost. All open files are closed automatically when the macro ends. See OpenFile. | |||
| Examples | Appendix A: 8088 | |||
| Return Value | True if successful, False if not. | |||
| Syntax |
|
|||
| Parameters |
|
|
Condition |
| Purpose | Determine how a macro responds to a Cancel, Error, NotFound, or user-defined condition. | |||||||||||||||||||||||||||
| Return Value |
|
|||||||||||||||||||||||||||
| Examples |
If Cancel is On! to start, the following two lines return the following results. vCnd1 := Condition (CancelCondition!; Off!) Result := vCnd1 = On! (condition was On!, now is Off!) vCnd2 := Condition (CancelCondition!; On!) Result := vCnd2 = Off! (condition was Off!, now is On!) |
|||||||||||||||||||||||||||
| Syntax |
|
|||||||||||||||||||||||||||
| Parameters |
|
|
Constant |
| Purpose |
Define a constant variable (an identifier whose value cannot change at run-time). Constants make macros easier to read. For example, Constant (Start := 0; Stop := 1) defines two constants. Start is replaced by 0 wherever it occurs in the macro, and Stop by Constants are compile-time only commands that are constant from the point of declaration to the end of the macro. All constants have a single value (array constants are not accepted), and cannot appear on the left side of subsequent assignment statements (or a compile-time error occurs). Separate multiple definitions with a semicolon. Parentheses are optional. Constant (Inch := 2.54C; Diameter := Inch) Constant Radius := 10I Constant (Tel :="222-5555") Constant Team := "Dan, Steve, Alan, Barry, Jimmy, Dave" |
||
| Syntax |
|
|
Constants |
| Purpose |
Get various mathematical and physical constants. |
|||||||||||||||
| Return Value | A constant. | |||||||||||||||
| Syntax |
|
|||||||||||||||
| Parameters |
|
|
Continue |
| Purpose | Execute the code in the next CaseOf statement without evaluating its expression. See Switch. |
| Syntax | Continue |
|
ConvertType |
| Purpose |
Convert a value to a specified data type. If Value is a number and Type is a measurement, or if Value is a measurement and Type is a number, a measurement conversion is also applied to the magnitude of the value to convert between the measurement and the type specified by DefaultUnitsType. You can prevent this by specifying None! for DefaultUnitsType. If both Value and Type are measurements, or if both are numbers, DefaultUnitsType is not used. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Return Value | Converted data type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Examples |
vTestValue := 72 vResult = ConvertType( vTestValue; Centimeters!; Points!) Result: vResult = 2.54C |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Syntax |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Parameters |
|
|
CopyFile |
| Purpose | Copy a file. | ||||||||||||||
| Examples | Appendix A: 8078 | ||||||||||||||
| Return Value | True if successful, False if not. | ||||||||||||||
| Syntax |
|
||||||||||||||
| Parameters |
|
|
cos |
| Purpose | Get the cosine of an angle in radians. | |||
| Return Value | Cosine of an angle. | |||
| Syntax |
|
|||
| Parameters |
|
|
cosh |
| Purpose | Get the hyperbolic cosine of an angle in radians. | |||
| Return Value | Hyperbolic cosine of an angle. | |||
| Syntax |
|
|||
| Parameters |
|
|
CreateDirectory |
| Purpose | Create a directory. | |||||||||||
| Examples | Appendix A: 8080 | |||||||||||
| Return Value | True if successful, False if not. | |||||||||||
| Syntax |
|
|||||||||||
| Parameters |
|
|
CreateObject |
| Purpose | Create a new instance of an OLE object. | |||
| Return Value | Instance that identifies an OLE object. After an OLE object variable is assigned an object instance, commands can be called, and values obtained and set for the object variable. When the object and variable are no longer needed, use the Discard command to destroy the object instance. | |||
| Syntax |
|
|||
| Parameters |
|
|
CToN |
| Purpose | Convert a character to its numeric equivalent. | |||
| Examples | Appendix A: 8012 | |||
| Return Value | Numeric equivalent of a character. | |||
| Syntax |
|
|||
| Parameters |
|
|
CubeRoot |
| Purpose | Get the cube root of a value. | |||
| Return Value | Cube root. | |||
| Syntax |
|
|||
| Parameters |
|