Appendix A
Corel® PerfectScript™ Examples
8000
APPLICATION (A1; “WordPerfect”; Default; “US”)
// Execute Windows* Notepad three times: full screen, normal size, and to an icon
// FORNEXT decrements initial value
// Demonstrate APPEXECUTE command
FORNEXT(vCtrl; 3; 1; -1)
VReturn = APPEXECUTE(“c:\windows\notepad.exe”; vCtrl)
IF(vReturn 32)
BEEP
MESSAGEBOX(vStatus; “ERROR”; “Unable to execute
notepad.exe"; IconExclamation!)
QUIT
ENDIF
WAIT(3)
ENDFOR
8001
APPLICATION(A1; “WordPerfect”; Default; “US”)// Execute Windows* Calculator
// Locate and activate 3 times
// Demonstrate APPEXECUTE command
ASSIGN(hWP; APPLOCATE(“*”))
APPEXECUTE(“c:\windows\calc.exe”)
ASSIGN(hCalc; APPLOCATE(“Calculator”))
FORNEXT(vCtrl; 1; 2; 1)
WAIT(10)
APPACTIVATE(hWP)
WAIT(10)
APPACTIVATE(hCalc)
ENDFOR
8002
APPLICATION(A1; “WordPerfect”; Default; “US”)// Display message box on ASSERT condition
// Demonstrate ASSERT command
ONCANCEL(Condition)
ONERROR(Condition)
ONNOTFOUND(Condition)
LABEL(Start)
MENU(vPick; Digit!; ; ; {“Assert Cancel”; “Assert Error”; “Assert Not Found”; “Quit”})
SWITCH(vPick)
CASEOF 1: ASSERT(CancelCondition!)
CASEOF 2: ASSERT(ErrorCondition!)
CASEOF 3: ASSERT(NotFoundCondition!)
CASEOF 4: QUIT
DEFAULT: GO(Condition)
ENDSWITCH
LABEL(Condition)
SWITCH(ErrorNumber)
CASEOF 1: vMsg := “1 (Cancel condition)”
CASEOF 2: vMsg := “2 (Error condition)”
CASEOF 7: vMsg := “3 (Not Found condition)”
DEFAULT: vMsg := “?”
ENDSWITCH
MESSAGEBOX(vStatus; “ASSERT COMMAND”; “You selected ” + vMsg; IconInformation!)
GO(Start)
8003
APPLICATION(A1; “WordPerfect”; Default; “US”)// Beep vCount times - BREAK when vCount equals 4
// Remember: functions do not execute unless called
// Demonstrate BEEP command
FUNCTION BeepBeep(vCount)
REPEAT
BEEP
WAIT(3)
vCount := vCount - 1
UNTIL(vCount = 0)
RETURN
ENDFUNC
FOREACH(vCount; {1; 2; 3; 4; 5})
IF(vCount = 4)
BREAK
ENDIF
BeepBeep(vCount)
WAIT(5)
ENDFOR
MESSAGEBOX(x; “BREAK”; “Variable vCount equals 4"; IconInformation!)
QUIT
8004
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Test user input
// Remember: procedures do not execute unless called
// Demonstrate GETNUMBER, PROCEDURE, and PROCEDURE PROTOTYPE commands
PROCEDURE PROTOTYPE ErrorMsg(x)
REPEAT
GETNUMBER(vNum; “Enter a number from 1 to 5"; ”GETNUMBER EXAMPLE")
IF((vNum 1) OR (vNum 5))
CALL ErrorMsg(vNum)
ELSE
MESSAGEBOX(vStatus; “YES!”; “You entered
“ + vNum; IconInformation!)
ENDIF
UNTIL((vNum 0) AND (vNum 6))
PROCEDURE ErrorMsg(x)
BEEP BEEP BEEP
IF(x 1)
vMessage := x + “ is less than 1"
ELSE
vMessage := x + “ is greater than 5"
ENDIF
MESSAGEBOX(vStatus; “OUT-OF-RANGE ERROR” ; vMessage + “ - please try again”; IconExclamation!)
ENDPROC
8005
APPLICATION(A1; “WordPerfect”; Default; “US”)
CANCEL(On!)
ONCANCEL CALL(CancelMessage)
PROCEDURE Message(vPrompt; vIcon)
IF(vIcon = “!”)
MESSAGEBOX(y; “Test Results”; vPrompt; IconExclamation!)
ELSE
MESSAGEBOX(y; “Test Results”; vPrompt; IconInformation!)
ENDIF
ENDPROC
vStr := “”
REPEAT
GETSTRING(vStr; “Enter a word or Q to quit.”; “Example Macro”; 50)
vTest := TOUPPER(vStr)
IF(vStr = “”)
vStr := “”"<OK>"""
ENDIF
IF(vTest = “Q”)
CALL Message(“Goodbye”; “i”)
ELSE
vMsg = “The CHAR length of ” + vStr
vMsg = vMsg + “ is ” + CHARLEN(vStr)
CALL Message(vMsg; “!”)
ENDIF
UNTIL(vTest = “Q”)
QUIT
LABEL(CancelMessage)
vStr := “ ”
RETURN
8006
APPLICATION(A1; “WordPerfect”; Default; “US”)
MENU(vChoice; Digit; ; ; {“Advance down”; “Advance up”; “Advance left”; “Advance right”})
SWITCH(vChoice)
CASEOF 1: vPrompt := “Advance down:”
CASEOF 2: vPrompt := “Advance up:”
CASEOF 3: vPrompt := “Advance left:”
CASEOF 4: vPrompt := “Advance right:”
ENDSWITCH
DEFAULTUNITS(Inches!)
// option: specifiy different unit of measure
GETUNITS(vUnit; vPrompt; “GETUNITS EXAMPLE”)
SWITCH(vChoice)
CASEOF 1: ADVANCE(AdvanceDown!; vUnit)
CASEOF 2: ADVANCE(AdvanceUp!; vUnit)
CASEOF 3: ADVANCE(AdvanceLeft!; vUnit)
CASEOF 4: ADVANCE(AdvanceRight!; vUnit)
ENDSWITCH
8007
APPLICATION(A1; “WordPerfect”; Default; “US”)// Execute Windows* Calculator, Calendar, and Cardfile
ASSIGN(hWP; APPLOCATE(“WordPerfect*”))
REPEAT
MENU(vChoice; Digit; ; ; {“Calculator”; “Calendar”; “Card File”; “Quit”})
CASE CALL(vChoice; {1; Program; 2; Program; 3; Program; 4; QuitMacro})
UNTIL(vChoice = 4)
LABEL(Program)
SWITCH(vChoice)
CASEOF 1: vProgram := “c:\windows\calc.exe”
CASEOF 2: vProgram := “c:\windows\calendar.exe”
CASEOF 3: vProgram := “c:\windows\cardfile.exe”
ENDSWITCH
APPEXECUTE(vProgram)
RETURN
LABEL(QuitMacro)
MESSAGEBOX(vStatus; “EXIT”; “Finished?”; IconQuestion! | YesNo!)
IF(vStatus = 6)
APPACTIVATE(hWP)
QUIT
ELSE
RETURN
ENDIF
8008
APPLICATION(A1; “WordPerfect”; Default; “US”)// Create personal or business letterhead
// Plays macro in WordPerfect for Windows
MENU(vChoice; Digit; ; ; {“Personal letterhead”; “Business letterhead”; “Quit”})
FileNew
CASE(vChoice; {1; Personal; 2; Business; 3; QuitMacro}; QuitMacro)
LABEL(Personal)
Center
AttributeAppearanceOn(Bold!)
FontSize(16.0p)
Type(“From Dan’s Desk”)
AttributeAppearanceOff(Bold!) HardReturn
Center FontSize(12.0p)
DateCode
HardReturn HardReturn HardReturn
Type(“Dear ”)
QUIT
LABEL(Business)
DateCode HardReturn HardReturn
Type(“Mr. John Doe”) HardReturn
Type(“Executive Vice President”) HardReturn
Type(“XYZ Company”) HardReturn
Type(“4399 Oak View Drive”) HardReturn
Type(“Orem, UT 84057") HardReturn HardReturn
Type(“Dear Mr. Doe:”)
QUIT
LABEL(QuitMacro)
QUIT
8009
// There are four macros in this example// Compile separately
APPLICATION(A1; “WordPerfect”; Default; “US”)
// macro1.wcm
MESSAGEBOX(vStatus; vTitle; “Macro 1 ” + vPrompt; IconInformation!)
APPLICATION(A1; “WordPerfect”; Default; “US”)
// macro2.wcm
MESSAGEBOX(vStatus; vTitle; “Macro 2 ” + vPrompt; IconInformation!)
APPLICATION(A1; “WordPerfect”; Default; “US”)
// macro3.wcm
MESSAGEBOX(vStatus; vTitle; “Macro 3 ” + vPrompt; IconInformation!)
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Calling Macro
GLOBAL vTitle; vPrompt
MENU(vChoice; Letter; ; ; {“Macro 1"; ”Macro 2"; “Macro 3"})
ASSIGN(vPrompt; “called”)
GETSTRING(vMacrosPath; “Enter macros path”; “Example Macro”; 50)
SWITCH(vChoice)
CASEOF 1:
ASSIGN(vTitle; “MACRO ONE”)
CHAIN(vMacrosPath + “macro1.wcm”)
CASEOF 2:
ASSIGN(vTitle; “MACRO TWO”)
CHAIN(vMacrosPath + “macro2.wcm”)
CASEOF 3:
ASSIGN(vTitle; “MACRO THREE”)
CHAIN(vMacrosPath + “macro3.wcm”)
ENDSWITCH
MESSAGEBOX(x; “Macro Example”; “This box displays before a Chain command is executed.”; IconInformation!)
8010
// There are four macros in this example// Compile separately
APPLICATION(A1; “WordPerfect”; Default; “US”)
// macro1.wcm
MESSAGEBOX(vStatus; vTitle; “Macro 1 - ” + vPrompt; IconInformation!)
RETURN
APPLICATION(A1; “WordPerfect”; Default; “US”)
// macro2.wcm
MESSAGEBOX(vStatus; vTitle; “Macro 2 - ” + vPrompt; IconInformation!)
RETURN
APPLICATION(A1; “WordPerfect”; Default; “US”)
// macro3.wcm
MESSAGEBOX(vStatus; vTitle; “Macro 3 - ” + vPrompt; IconInformation!)
RETURN
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Calling Macro
// Demonstrate RUN command and GLOBAL variables
GLOBAL vTitle; vPrompt
ASSIGN(vPrompt; “RUN macros can return to their caller”)
ASSIGN(vMacrosPath; EnvPaths(PathType: Macros!))
REPEAT
MENU(vChoice; Letter; ; ; {“Macro 1"; ”Macro 2"; “Macro 3"; ”Quit"})
SWITCH(vChoice)
CASEOF 1:
ASSIGN(vTitle; “MACRO ONE”)
RUN(vMacrosPath + “macro1.wcm”)
CASEOF 2:
ASSIGN(vTitle; “MACRO TWO”)
RUN(vMacrosPath + “macro2.wcm”)
CASEOF 3:
ASSIGN(vTitle; “MACRO THREE”)
RUN(vMacrosPath + “macro3.wcm”)
DEFAULT: QuitMacro
ENDSWITCH
UNTIL(vChoice = 4)
LABEL(QuitMacro)
BEEP
MESSAGEBOX(vStatus; “QUIT”; “This example uses global variables”; IconExclamation!)
DISCARD vTitle; vPrompt
QUIT
8011
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Create a loop with GO command
LABEL(Start)
MENU(vChoice; Digit; ; ; {“IconExclamation!”; “IconInformation!”; “IconQuestion”; “IconStop!”; “Quit”})
CASE(vChoice; {1; Exclaim; 2; Info; 3; Question; 4; Stop; 5; QuitMacro})
LABEL(Exclaim)
MESSAGEBOX(x; “EXCLAMATION”; “Example of an exclamation icon”; IconExclamation!)
GO(LoopToStart)
LABEL(Info)
MESSAGEBOX(x; “INFORMATION”; “Example of an information icon”; IconInformation!)
GO(LoopToStart)
LABEL(Question)
Yes := 6
MESSAGEBOX(vAns; “QUESTION”; “Example of a question icon” + NTOC(0F90Ah) +"Click a button"; IconQuestion! | YesNo!)
IF(vAns = Yes)
vPrompt := “You clicked Yes”
ELSE
vPrompt := “You clicked No ”
ENDIF
MESSAGEBOX(x; “MACRO PATH”; vPrompt; IconInformation!)
GO(LoopToStart)
LABEL(Stop)
MESSAGEBOX(z; “STOP”; “Example of a stop icon”; IconStop!)
GO(LoopToStart)
LABEL(LoopToStart)
No := 7
MESSAGEBOX(vAns; “Message”; “Would you like to continue?”; IconQuestion! | YesNo!)
IF(vAns = No)
GO(QuitMacro)
ELSE
vChoice = “”
GO(Start)
ENDIF
LABEL(QuitMacro)
BEEP
QUIT
8012
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Extract numbers from a character string
// Demonstrate CHARLEN command
vNumbers := “”
vPrompt := “Enter text that includes both letters and numbers:”
LABEL(Start)
GETSTRING(vStr; vPrompt; “EXTRACT NUMBERS”)
IF(vStr = “”)
BEEP
MESSAGEBOX(x; “ERROR”;
“You pressed return without entering any text”; IconStop!)
GO(Start)
ENDIF
vLen := CHARLEN(vStr)
vPos := 1
WHILE(NOT(vPos = vLen + 1))
vTest := SUBCHAR(vStr; vPos; 1)
IF((CTON(vTest) 47) AND (CTON(vTest) 58))
vNumbers := vNumbers + vTest
ENDIF
vPos := vPos + 1
ENDWHILE
IF(CHARLEN(vNumbers) 0)
MESSAGEBOX(x; “NUMBER STRING”;
“You entered the following numbers: ” + vNumbers;
IconInformation!)
ELSE
BEEP
MESSAGEBOX(x; “ERROR”; “You didn’t enter
any numbers"; IconExclamation!)
ENDIF
8013
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Extract “Perfect” from WordPerfect
// Test if “program” was entered
// Demonstrate SUBCHAR command
vNumbers := “”
vPrompt := “Enter the following text: ”"WordPerfect program"""
LABEL(Start)
GETSTRING(vStr; vPrompt; “USING SUBCHAR”)
IF(vStr = “”)
BEEP
MESSAGEBOX(x; “ERROR”; “You pressed return
without entering any text"; IconStop!)
GO(Start)
ENDIF
vSub := SUBCHAR(vStr; 5; 7)
IF(vSub = “Perfect”)
MESSAGEBOX(x; “SUBCHAR EXAMPLE”; “WordPerfect
is simply “”" + vSub + “”""; IconInformation!)
IF(CHARPOS(vStr; “program”) = 0)
BEEP
MESSAGEBOX(x; “CHARPOS EXAMPLE”; “You entered
ENDIF
ELSE
BEEP
MESSAGEBOX(x; “ERROR”; “”"WordPerfect"" wasn’t the first word";
IconExclamation!)
GO(Start)
ENDIF
8014
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Start conversation with GroupWise* 4.1
// Demonstrate DDEEXECUTE and DDEINITIATE commands
hConv := DDEINITIATE(“GROUPWISE”; “COMMAND”)
IF(hConv) // IF hConv not equal to 0
DDEEXECUTE(hConv; “ViewOpenNamed(ViewName:”"Mail""; ViewType:Mail!)")
DDETERMINATEALL
ELSE
MESSAGEBOX(x; “ERROR”; “Is GroupWise running? Conversation not started.”; IconQuestion!)
ENDIF
8015
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Start conversation with GroupWise* 4.1 from WordPerfect 6.1
// Execute GroupWise 4.1 command
// Demonstrate DDEEXECUTEEXT command
ASSIGN(hConv; DDEINITIATE(“GROUPWISE”; “COMMAND”))
IF(hConv) // IF hConv not equal to 0
vReturn := DDEEXECUTEEXT(hConv; “ViewOpenNamed(”"Mail""; Mail!)"; 0; Message)
IF(vReturn = 0)
MESSAGEBOX(x; “ERROR”; “Command not received by GroupWise”; IconExclamation!)
ENDIF
ELSE
BEEP
MESSAGEBOX(x; “ERROR”; “Is GroupWise running? Conversation not started.”; IconQuestion!)
ENDIF
DDETERMINATEALL
QUIT
LABEL(Message)
ASSIGN(vMsg; “GroupWise acknowledges receipt of ViewOpenNamed command”)
MESSAGEBOX(z; “DDEEXECUTEEXT EXAMPLE”; vMsg; IconInformation!)
RETURN
8016
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Request GroupWise* 4.1 version number from WordPerfect 7
// Demonstrate DDEREQUEST command
// This example is included for backward compatibility
// In GroupWise Macros Help, see Contents page, Using DDE
ASSIGN(hConv; DDEINITIATE(“WPOFFICE40"; ”GETOFFICEDATA"))
IF(hConv)
ASSIGN(vMajor; DDEREQUEST(hConv; “GetOfficeData(ID; MajorVersion!)”))
ASSIGN(vMinor; DDEREQUEST(hConv; “GetOfficeData(ID; MinorVersion!)”))
MESSAGEBOX(x; “DDEREQUEST EXAMPLE”; “GroupWise version is ” + vMajor + “.” + vMinor; IconInformation!)
DDETERMINATE(hConv)
ELSE
BEEP
MESSAGEBOX(x; “ERROR”; “Is GroupWise running? Conversation not started.”; IconQuestion!)
ENDIF
8017
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Assign fax number to ExpressFax+
// Demonstrate DDEPOKE command
ASSIGN(hConv; DDEINITIATE(“FAXMNG”; “Transmit”))
IF(hConv)
GETSTRING(vFax; “Enter FAX Number”; “ExpressFax+”)
DDEPOKE(hConf;"FAX Number"; vFax)
DDETERMINATE(hConv)
ELSE
BEEP
MESSAGEBOX(x; “ERROR”; “Is ExpressFax+ running? Conversation not started.”; IconQuestion!)
ENDIF
8018
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Declare an array of months
// Demonstrate DECLARE command, recursive LABEL statement
DECLARE Months[12]
x := 1
FOREACH(vMonth; {“January”; “February”; “March”; “April”; “May”; “June”; “July”; “August”; “September”; “October”; “November”; “December”})
Months[x] := vMonth
x := x + 1
ENDFOR
LABEL(Start)
MENU(vNmbr; Letter; ; ; {“January”; “February”; “March”; “April”; “May”; “June”; “July”; “August”; “September”; “October”; “November”; “December”; “QUIT”})
IF(vNmbr = 13)
BEEP
QUIT
ELSE
MESSAGEBOX(vStatus; “MONTHS OF THE YEAR”;
“You selected ” + Months[vNmbr]; IconInformation!)
GO(Start)
8020
ENDIF APPLICATION(A1; “WordPerfect”; Default; “US”)
// LABEL(ErrorMsg) executes with ERROR(On!)
// Demonstrate ERROR command
ONERROR(ErrorMsg)
REPEAT
MENU(vChoice; Digit; ; ; {“ERROR(Off!)”; “ERROR(On!)”; “Quit”})
CASE CALL(vChoice; {1; OffMsg; 2; OnMsg; 3; QuitMacro}; QuitMacro)
UNTIL(vChoice = 3)
LABEL(OffMsg)
ERROR(Off!)
ASSERT(ErrorCondition!) // ignore Error condition
MESSAGEBOX(x; “ERROR(Off!)”; “Error condition ignored”; IconInformation!)
RETURN
LABEL(OnMsg)
ERROR(On!)
ASSERT(ErrorCondition!) // LABEL(ErrorMsg) executed
RETURN
LABEL(ErrorMsg)
BEEP
MESSAGEBOX(x; “ERROR CONDITION”; “An error condition causes LABEL(ErrorMsg) to execute”; IconInformation!)
RETURN
LABEL(QuitMacro)
QUIT
8021
APPLICATION(A1; “WordPerfect”; Default; “US”)
// LABEL(NotFoundMsg) executes with NOTFOUND(On!)
// Demonstrate NOTFOUND command
ONNOTFOUND(NotFoundMsg)
REPEAT
MENU(vChoice; Digit; ; ; {“NOTFOUND(Off!)”; “NOTFOUND(On!)”; “Quit”})
CASE CALL(vChoice; {1; OffMsg; 2; OnMsg; 3; QuitMacro}; QuitMacro)
UNTIL(vChoice = 3)
LABEL(OffMsg)
NOTFOUND(Off!)
ASSERT(NotFoundCondition!) // ignore Not Found condition
MESSAGEBOX(x; “NOTFOUND(Off!)”; “Not Found condition ignored”; IconInformation!)
RETURN
LABEL(OnMsg)
NOTFOUND(On!)
ASSERT(NotFoundCondition!) // LABEL(NotFoundMsg) executed
RETURN
LABEL(NotFoundMsg)
BEEP
MESSAGEBOX(x; “NOTFOUND CONDITION”;
“A Not Found condition causes LABEL(NotFoundMsg) to execute”; IconInformation!)
RETURN
LABEL(QuitMacro)
QUIT
8022
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Declare and test variable types
// Demonstrate BREAK, EXISTS, LOCAL, GLOBAL, and PERSIST commands
DISCARD var5; var1; var7
LOCAL var2; var9; var4
GLOBAL var3; var10; var6
PERSIST var5; var1; var7
ASSIGN(var8; “”)
FOR(x; 1; x 11; x + 1)
ASSIGN(INDIRECT(“var” + x); x)
MESSAGEBOX(vStatus; “VAR” + x; “Continue to next variable?”; IconQuestion! | YesNo!)
IF(vStatus = 7)
BREAK
ENDIF
ENDFOR
FOR(z; 1; z (x + 1); z + 1)
SWITCH(EXISTS(INDIRECT(“var” + z)))
CASEOF 1: Msg(“Local”; z)
CASEOF 2: Msg(“Global”; z)
CASEOF 3: Msg(“Persist”; z)
ENDSWITCH
ENDFOR
FUNCTION Msg(w; y)
MESSAGEBOX(z; “VARIABLE TYPES”; “var” + y + “ = ” + w)
ENDFUNC
8023
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Calculate fractions and integers
// Demonstrate FRACTION and INTEGER commands
ONCANCEL(QuitMacro)
ASSIGN(HdReturn; NTOC(0F90Ah)) // hard return code
REPEAT
GETNUMBER(vNmbr; “Enter a real number:”; “FRACTION EXAMPLE”)
ASSIGN(vInteger; INTEGER(vNmbr))
ASSIGN(vFraction; FRACTION(vNmbr))
vMsg1 := “The integer portion of ” + vNmbr + “ is ” + vInteger
vMsg2 := “The fractional portion of ” + vNmbr + “ is ” + vFraction
MESSAGEBOX(x; “INTEGER - FRACTION”; vMsg1 + HdReturn + HdReturn + vMsg2 + HdReturn; IconInformation! | RetryCancel!)
UNTIL(x = 2)
LABEL(QuitMacro)
QUIT
8024
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Remember: functions must be called to execute
// Demonstrate FUNCTION and FUNCTION PROTOTYPE commands
FUNCTION PROTOTYPE Check(vBeep; HdReturn)
HdReturn := NTOC(0F90Ah)
x := 4
vBeep := 1
WHILE(x = 4)
BEEP
x := Check(vBeep; HdReturn)
vBeep := vBeep + 1
ENDWHILE
MESSAGEBOX(z; “RETURN”; “The value of variable vStatus (” + x + “) is returned to variable x, which ends the loop.”; IconExclamation!)
FUNCTION Check(vBeep; HdReturn)
MESSAGEBOX(vStatus; “FUNCTION EXAMPLE”; “Beeps: ” + vBeep + HdReturn + HdReturn + “Choose Retry to beep again.” + HdReturn; IconInformation! | RetryCancel!)
RETURN(vStatus)
ENDFUNC
8025
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Play .wav file
// Assume Windows* sound system and that appropriate driver is installed
// Demonstrate MMPLAY and WAIT commands
No := 7
REPEAT
MENU(vWav; Digit; ; ; {“Siren”; “Crickets”; “Snoring”; “Thunder”; “Dog bark”; “Elephant”; “Quit”})
SWITCH(vWav)
CASEOF 1: PlaySound(“siren.wav”; 115)
CASEOF 2: PlaySound(“crickets.wav”; 50)
CASEOF 3: PlaySound(“snoring.wav”; 30)
CASEOF 4: PlaySound(“thunder.wav”; 30)
CASEOF 5: PlaySound(“dogbark.wav”; 15)
CASEOF 6: PlaySound(“elephant.wav”; 15)
CASEOF 7: QUIT
ENDSWITCH
MESSAGEBOX(vStatus; “MMPLAY”; “Would you like to hear another sound?”; IconQuestion! | YesNo!)
UNTIL(vStatus = No)
PROCEDURE PlaySound(vSound; vWait)
MMPLAY(“c:\windows\sndsys\sounds\” + vSound)
WAIT(vWait)
ENDPROC
8026
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Speak an ASCII text file
// A text-to-speech driver must be installed
// Demonstrate MMSPEAK, MMSPEAKCLIPBOARD, MMSTOPSPEECH commands
REPEAT
MENU(vChoice; Digit; ; ; {“File”; “Clipboard”; “Quit”})
SWITCH(vChoice)
CASEOF 1:
GETSTRING(vStr; “Enter the path and name
of a file to speak:"; “ASCII TEXT FILE”)
IF(vStr = “”)
BREAK
ELSE
MMSPEAK(vStr)
CancelMessage()
ENDIF
CASEOF 2:
MMSPEAKCLIPBOARD
CancelMessage()
ENDSWITCH
UNTIL(vChoice = 3)
QUIT
PROCEDURE CancelMessage()
vCancel := 2
MESSAGEBOX(vStatus; “SPEAK FILE”; “Choose Cancel any time to stop speech”; IconStop! | RetryCancel!)
IF(vStatus = vCancel)
MMSTOPSPEECH
ENDIF
ENDPROC
8027
APPLICATION(A1; “WordPerfect”; Default; “US”)
APPLICATION(A2; “WordPerfect”; “US”)
// AboutDlg does not require a product prefix
AboutDlg()
NEWDEFAULT(A2)
// WordPerfect is not the default application
// AboutDlg requires a product prefix (A2)
A2.AboutDlg()
8028
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Convert integer to Character equivalent
// NTOC(32) returns “space” character
// Demonstrate NTOC command
AddTextBox (1000w;9000w;12000w;8000w)
FOR(int; 33; int 127; int + 1)
Type(NTOC(int) + (NTOC(32)))
ENDFOR
// Convert character set value to character equivalent
FOR(int; 0; int 102; int + 1)
Type(NTOC(4; int) + (NTOC(32)))
ENDFOR
MESSAGEBOX(vAns; “NTOC command”; “Close Text Box?”; YesNo! | IconQuestion!)
IF(vAns = 6)
TextEditExit()
ENDIF
8030
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Test Error condition
// Demonstrate ONERROR CALL command
ONERROR CALL(ErrorTest)
No := 7
REPEAT
GETNUMBER(vNmbr; “Enter 3 and press
:”; “ONERROR CALL EXAMPLE”)
IF(vNmbr = 3)
MESSAGEBOX(vStatus; “YES!”; “You entered
ELSE
ASSERT(ErrorCondition!)
ENDIF
UNTIL(vStatus = No)
QUIT
LABEL(ErrorTest)
BEEP
MESSAGEBOX(vStatus; “ERROR”; “You didn’t enter 3 as requested”; IconExclamation!)
RETURN
8031
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Test Not Found condition
// Open view and retrieve text into the message box
// Demonstrate ONNOTFOUND command
NOTFOUND(On!)
ONNOTFOUND CALL(NotFoundTest)
No := 7
REPEAT
GETSTRING(vStr; “Enter a string to search for and press :”;
“ONNOTFOUND CALL EXAMPLE”)
IF(vStr = “”)
NEXT
ENDIF
vError := False
PosTextTop()
Find(MessageSearchString: vStr; SearchDir: Forward!; MessageMatch: BeginText!)
IF(vError = False)
vMessage := “Success! Do you want to try again?”
ELSE
vMessage := “Not Found condition. Do you
want to try again?"
ENDIF
MESSAGEBOX(vStatus; “Search”; vMessage; IconInformation! | YesNo!)
UNTIL(vStatus = No)
QUIT
LABEL(NotFoundTest)
BEEP
MESSAGEBOX(vError; “ERROR”; “”"" + vStr + “”" not found"; IconExclamation!)
vError := True
RETURN // return to IF statement following Find command
8032
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Demonstrate PAUSE command
ONCANCEL(EndLoop)
InhibitInput(Off!)
InformationIcon := 4
x := 1
AddTextBox(1000w;9000w;12000w;8000w;)
REPEAT
Type(x + NTOC(32))
IF(x MOD 10 = 0)
PROMPT(“PAUSE EXAMPLE”;
“Choose OK to dismiss dismiss prompt and continue loop, or Cancel to end loop.”;
InformationIcon)
PAUSE
ENDIF
x := x + 1
UNTIL(x = 0)
LABEL(EndLoop)
QUIT
8033
// There are two macros in this example
// Compile separately
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Name of macro: Persist.wcm
// Demonstrate PERSIST command
// vNmbr is a Persist variable
MESSAGEBOX(x; “PERSISTALL EXAMPLE”; “The value of variable vNmbr is ” + vNmbr; IconInformation!)
ASSIGN(vNmbr; 999)
RETURN
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Run PERSIST.WCM macro
// Demonstrate PERSISTALL command
LOCAL vStatus; vCancel
vStatus := 4
vCancel := 2
PERSISTALL // vNmbr Persist variable
REPEAT
IF(EXISTS(vNmbr))
DISCARD vNmbr
ENDIF
GETNUMBER(vNmbr; “Enter a number:”; “PERSISTALL EXAMPLE”)
vMacrosPath := EnvPaths(Macros!)
RUN(vMacrosPath + “persist.wcm”)
MESSAGEBOX(vStatus; “PERSISTALL EXAMPLE”;
“After running PERSIST.WCM, the value of variable vNmbr is ” + vNmbr; IconInformation! | RetryCancel!)
UNTIL(vStatus = vCancel)
8034
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Saves text to file
// Demonstrate SENDKEYS WAIT command
InhibitInput(Off!)
AddTextBox(1000w;9000w;12000w;8000w;)
Type(“Save this message as ”"test.doc"" in the default Save Directory (see PrefLocationOfFiles).")
WAIT(10)
SENDKEYS WAIT(“{Alt+F}{S}test.doc{Enter}”)
8035
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Demonstrate SPEED command
ONCANCEL(QuitMacro)
AddTextBox(1000w;9000w;12000w;8000w;)
Type(“Press Ctrl+Shift+F10 to Cancel”)
FOR(x; 1; x 51; x + 1)
Type(x + NTOC(32))
SPEED(x/10)
IF(((x MOD 10) = 0) AND (x 50))
Slower
ENDIF
ENDFOR
QuitMacro
LABEL(Slower)
BEEP
Type(“Slower ... ”)
RETURN
LABEL(QuitMacro)
MESSAGEBOX(x; “SPEED EXAMPLE”; “Counting to 50, SPEED increased the delay between counts.”; IconInformation!)
QUIT
8036
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Test user input for Y or N
// For Cancel condition: chose Cancel, click Close, press Alt+F4, or double-click system menu box
// Demonstrate STRLEN command
CANCEL(On!)
ONCANCEL CALL(CancelMessage)
PROCEDURE Message(vPrompt; vIcon)
IF(vIcon = “!”)
BEEP
MESSAGEBOX(y; “Message Box”; vPrompt; IconExclamation!)
ELSE
MESSAGEBOX(y; “Message Box”; vPrompt; IconInformation!)
ENDIF
ENDPROC
vStr := “”
REPEAT
GETSTRING(vStr; “Press one character: ”"Y"" for Yes or “”N"" for no";
“GETSTRING - STRLEN EXAMPLE”; 50)
IF(vStr = “”)
vStr := “
”
ENDIF
vTest := TOUPPER(vStr)
IF(STRLEN(vStr) 1)
CALL Message(“You typed or pressed ”"" +
vStr + “”""; “!”)
ELSE
IF((vTest = “Y”) OR (vTest = “N”))
CALL Message(“Well done - You pressed ” +
vTest; “i”)
ELSE
CALL Message(“You pressed ”"" + vStr + “”""; “!”)
ENDIF
ENDIF
UNTIL(((vTest = “Y”) OR (vTest = “N”)) AND NOT(STRLEN(vStr) 1))
QUIT
LABEL(CancelMessage)
vStr := “a Cancel control”
RETURN
8037
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Extract string of numbers and convert to numeric equivalent
// Demonstrate STRNUM command
vNumbers := “”
vPrompt := “Enter text that includes both letters and numbers:”
LABEL(Start)
GETSTRING(vStr; vPrompt; “EXTRACT NUMBERS”)
IF(vStr = “”)
BEEP
MESSAGEBOX(x; “ERROR”; “You pressed return
without entering any text"; IconStop!)
GO(Start)
ENDIF
vLen := STRLEN(vStr)
vPos := 1
REPEAT
vTest := SUBSTR(vStr; vPos; 1)
IF((CTON(vTest) 47) AND (CTON(vTest) 58))
vNumbers := vNumbers + vTest
ENDIF
vPos := vPos + 1
UNTIL(vPos = vLen + 1)
IF(STRLEN(vNumbers) 0)
vConvert := STRNUM(vNumbers)
vConvert := vConvert * 5
MESSAGEBOX(x; “STRNUM COMMAND”; vNumbers
+ “ * 5 equals ” + vConvert; IconInformation!)
ELSE
BEEP
MESSAGEBOX(x; “ERROR”; “You didn’t enter any numbers”; IconExclamation!)
ENDIF
8038
APPLICATION(A1; “WordPerfect”; Default; “US”)
// Extract string of numbers and convert to measurement equivalent
// Demonstrate STRUNIT command
Retry := 4
LABEL(Start)
vNumbers := “”
GETSTRING(vStr; “Enter text that includes both letters and numbers:”; “EXTRACT NUMBERS”)
IF(vStr = “”)
BEEP
MESSAGEBOX(x; “ERROR”; “You pressed return
without entering any text"; IconStop!)
GO(Start)
ENDIF
vLen := STRLEN(vStr)
vPos := 1
REPEAT
vTest := SUBSTR(vStr; vPos; 1)
IF((CTON(vTest) 47) AND (CTON(vTest) 58))
vNumbers := vNumbers + vTest
ENDIF
vPos := vPos + 1
UNTIL(vPos = vLen + 1)
IF(STRLEN(vNumbers) 0)
CALL(DefaultUnit)
vConvert := STRUNIT(vNumbers)
vConvert := vConvert * 5
MESSAGEBOX(x; “STRUNIT COMMAND”; vNumbers
IF(x = Retry)
GO(Start)
ENDIF
ELSE
BEEP
MESSAGEBOX(x; “ERROR”; “You didn’t enter
any numbers"; IconExclamation!)
ENDIF
QUIT
LABEL(DefaultUnit)
MENU(vChoice; Digit; ; ; {“Inches”; “Centimeters”; “Millimeters”; “Points”; “WP Units”})
SWITCH(vChoice)
CASEOF 1: DEFAULTUNITS(Inches!)
CASEOF 2: DEFAULTUNITS(Centimeters!)
CASEOF 3: DEFAULTUNITS(Millimeters!)
CASEOF 4: DEFAULTUNITS(Points!)
CASEOF 5: DEFAULTUNITS(WPUnits!)
ENDSWITCH
RETURN