home *** CD-ROM | disk | FTP | other *** search
/ Chip: 25 Years Anniversary / CHIP_25Jahre_Jubilaeum.iso / downloads / 401065 / WPO11 / Data1.cab / _A0E84D1BD1F24AD797C5059AE27ABA15 < prev    next >
Text File  |  2003-03-07  |  86KB  |  2,657 lines

  1. Reference: Merging
  2.  
  3. Reference: The Merge toolbar and programming commands
  4.  
  5. The Merge toolbar displays at the top of the document window when you create a form document or a data file for a merge. You can control a merge and edit merge files by using the Merge toolbar.
  6.  
  7. You can also control a merge by using merge programming commands. The merge commands are similar to codes used in computer programming languages. For example, you need to specify parameters for some commands, and you can create subroutines, a set of commands that can be repeated in a merge.
  8.  
  9. Using the Merge toolbar
  10.  
  11. When you create a form document or a data file for a merge, the Merge toolbar displays at the top of the document window.
  12.  
  13. You can control a merge and perform specific merge functions by using the Merge toolbar. The Merge toolbar is context-sensitive, which means that the buttons available on the Merge toolbar change according to the task you are performing. For example, you would see different buttons for performing a keyboard merge and for editing a data table file.
  14.  
  15. You cannot hide the Merge toolbar for a merge form document or merge data file. If it is not visible, then the active file is not a form document or a merge data file.
  16.  
  17. Prompting for user input and message display
  18.  
  19. Several commands are used to display a message for, or request information from, the person running the merge. You can use a message to inform the user of the progress of the merge or you can use a prompt to remind the user of the kind of information needed in a fill-in form.
  20.  
  21. The following table lists commands displaying a message or prompt and shows how they differ from each other:
  22.  
  23.  
  24.  
  25. Command    Action and user input
  26.  
  27. PROMPT (followed by WAIT)    Displays message for the duration of the WAIT command; no user input is required.
  28.  
  29. STATUSPROMPT    Displays message until another message is displayed; no user input is required.
  30.  
  31. KEYBOARD    Displays message and asks for keyboard input; text is inserted in the document. The user types information and clicks Continue on the Merge toolbar (or presses Alt + Enter).
  32.  
  33. GETSTRING    Displays message and asks for keyboard input; text is assigned to a variable. The user types information and presses Enter.
  34.  
  35. CHAR    Displays message and asks for one-character input; the character is assigned to a variable. The user types one character.
  36.  
  37. LOOK    No message; checks whether a key has been pressed. If a key has been pressed, the key is assigned to a variable; otherwise, the variable is deleted. The user types one character or nothing (merge does not pause for input).
  38.  
  39.  
  40.  
  41. Reusing commands with subroutines
  42.  
  43. You can create a subroutine to call a set of commands which are repeated several times in a merge. You do not need to add them each time. You can add them once, label them as a subroutine, then return to them (or call them) each time you want them to run.
  44.  
  45. The three commands used to define and call a subroutine are described in the following table.
  46.  
  47.  
  48.  
  49. Command    Action and user input
  50.  
  51. CALL(label)    Stops the merge and directs it to execute the subroutine. The label parameter must match the name of the label.
  52.  
  53. LABEL(labelname)    Marks the beginning of the subroutine. The labelname parameter is a unique name that identifies the subroutine.
  54.  
  55. RETURN    Marks the end of the subroutine and returns the merge to the line after the CALL command. If you do not add the RETURN command, the merge will continue in an infinite loop or will not continue correctly.
  56.  
  57.  
  58.  
  59. Using multiple files and macros in a merge
  60.  
  61. A merge can consist of more than one data file or form file, and it can include multiple macros. This may be useful if you want to merge different documents with the same data or if you have multiple data sources to merge. There are three ways to connect merge files: nesting, chaining, and substituting.
  62.  
  63. Nesting
  64.  
  65. Nesting a file or macro is like calling a subroutine. The merge pauses while the nested file or macro runs, then continues after the nested file has finished. This is useful if you use certain procedures frequently in your merges because you can save them in smaller files.
  66.  
  67. You can have multiple levels of nesting, a merge file can nest a second file or macro, which in turn nests another file, and so on. The three nest commands are described in the following table.
  68.  
  69.  
  70.  
  71. Command    Action and user input
  72.  
  73. NESTDATA(filename)    Changes to another data source. After that data has been merged with the form file, the merge returns to the first data source. Include a full path with the filename.
  74.  
  75. NESTFORM(filename)    Pauses the merge and changes to another form file. After that file has merged completely, the original merge continues. Include a full path with the filename.
  76.  
  77. NESTMACRO(macroname)    Pauses the merge, plays the macro, then continues the merge after the macro ends. You do not need to add a full path or the .wcm filename extension to the name of the macro.
  78.  
  79.  
  80.  
  81. Chaining
  82.  
  83. Chaining another file or macro starts that file or macro when the original merge is finished. This is one way to run multiple merges one after the other instead of starting each one manually. Only one chain command is used in a merge file; if there is more than one, the last one is used. The three chain commands are described in the following table.
  84.  
  85.  
  86.  
  87. Command    Action and user input
  88.  
  89. CHAINDATA(filename)    Merges records from the second file when all records from the first data source have been merged. Include a full path with the filename.
  90.  
  91. CHAINFORM(filename)    Merges the new form file when the original form file has finished. Include a full path with the filename.
  92.  
  93. CHAINMACRO(macroname)     Plays the macro after the merge has finished. You do not need to add a full path or the .wcm filename extension to the name of the macro.
  94.  
  95.  
  96.  
  97. Substituting
  98.  
  99. Substituting another form or data file is another way to change from one merge file to another. However, a substitute command moves the merge immediately to the second file without finishing the original merge file. When this happens, the new merge does not return to the original merge. The two substitute commands are described in the following table.
  100.  
  101.  
  102.  
  103. Command    Action and user input
  104.  
  105. SUBSTDATA(filename)    Changes to the new data file and begins merging its records. Include a full path with the filename.
  106.  
  107. SUBSTFORM(filename)    Changes to the new form file and begins executing the merge commands in the file. Include a full path with the filename.
  108.  
  109.  
  110.  
  111. Understanding merge code parameters
  112.  
  113. Most merge programming codes use parameters (also called arguments). In the following table, parameters are enclosed in parentheses and any optional parameters are enclosed in square brackets. When there are two or more parameters, they are separated with a semicolon.
  114.  
  115. Merge code parameters
  116.  
  117. You need to enter the correct parameters and arguments as required for the merge code. The following table lists parameters and their arguments.
  118.  
  119.  
  120.  
  121. Parameter    What you do
  122.  
  123. (expr);(subexpr)    Enter a number, string, variable, command, expression, or combination of these
  124.  
  125. (label)    Enter a unique label name
  126.  
  127. (var)    Enter a unique variable name
  128.  
  129. (field)    Enter a unique name or field number
  130.  
  131. (filename)    Enter a filename, including the full path
  132.  
  133. (macroname)    Enter a unique macro name; the full path is optional and no .wcm extension is needed.
  134.  
  135. (title)    Enter the title of the dialog box
  136.  
  137. (prompt);(message)    Enter information to display on the screen
  138.  
  139. (comment)    Enter a description of what the merge does; this does not display on screen.
  140.  
  141.  
  142.  
  143. Merge programming commands
  144.  
  145. WordPerfect merge programming commands let you program a merge. Many commands are similar to those in other programming languages. The following commands can be used in merge. For more information about each command, click on the command name to link to the command's Help topic. For information on merging, see "Merging documents."
  146.  
  147. ASSIGN(var;expr)
  148.  
  149. ASSIGNLOCAL(var;expr)
  150.  
  151. BEEP
  152.  
  153. BREAK
  154.  
  155. CALL(label)
  156.  
  157. CANCELOFF
  158.  
  159. CANCELON
  160.  
  161. CAPS(expr)
  162.  
  163. CASEOF(expr[;...;expr])
  164.  
  165. CHAINDATA(filename)
  166.  
  167. CHAINFORM(filename)
  168.  
  169. CHAINMACRO(macroname)
  170.  
  171. CHAR(var[;prompt][;title])
  172.  
  173. CODES(merge codes)
  174.  
  175. COMMENT(comment)
  176.  
  177. CONTINUE
  178.  
  179. CTON(character)
  180.  
  181. DATE
  182.  
  183. DEFAULT
  184.  
  185. DISPLAYSTOP
  186.  
  187. DOCUMENT(filename)
  188.  
  189. ELSE
  190.  
  191. EMBEDMACRO(macro statements)
  192.  
  193. ENDFIELD
  194.  
  195. ENDFOR
  196.  
  197. ENDIF
  198.  
  199. ENDRECORD
  200.  
  201. ENDSWITCH
  202.  
  203. ENDWHILE
  204.  
  205. FIELD(field)
  206.  
  207. FIELDNAMES(name1;...;nameN)
  208.  
  209. FIRSTCAP(expr)
  210.  
  211. FOREACH(var;expr1;...;exprN)
  212.  
  213. FORNEXT(var;start;stop[;step])
  214.  
  215. GETSTRING(var[;prompt][;title])
  216.  
  217. GO(label)
  218.  
  219. IF(expr)
  220.  
  221. IFBLANK(field)
  222.  
  223. IFEXISTS(var)
  224.  
  225. IFNOTBLANK(field)
  226.  
  227. INSERT(text)
  228.  
  229. KEYBOARD([prompt])
  230.  
  231. LABEL(label)
  232.  
  233. LOOK(var)
  234.  
  235. MRGCMND(merge codes)
  236.  
  237. NESTDATA(filename)
  238.  
  239. NESTFORM(filename)
  240.  
  241. NESTMACRO(macroname)
  242.  
  243. NEXT
  244.  
  245. NEXTRECORD
  246.  
  247. NTOC(number)
  248.  
  249. ONCANCEL(action)
  250.  
  251. ONERROR(action)
  252.  
  253. PAGEOFF
  254.  
  255. PAGEON
  256.  
  257. POSTNET(string)
  258.  
  259. PRINT
  260.  
  261. PROCESSOFF
  262.  
  263. PROCESSON
  264.  
  265. PROMPT(message)
  266.  
  267. QUIT
  268.  
  269. REPEATROW
  270.  
  271. RETURN
  272.  
  273. RETURNCANCEL
  274.  
  275. RETURNERROR
  276.  
  277. REWRITE
  278.  
  279. STATUSPROMPT(message)
  280.  
  281. STEPOFF
  282.  
  283. STEPON
  284.  
  285. STOP
  286.  
  287. STRLEN(expr)
  288.  
  289. STRPOS(expr;subexpr)
  290.  
  291. SUBSTDATA(filename)
  292.  
  293. SUBSTFORM(filename)
  294.  
  295. SUBSTR(expr;start;length)
  296.  
  297. SWITCH(expr)
  298.  
  299. SYSTEM(sysvar)
  300.  
  301. TOLOWER(expr)
  302.  
  303. TOUPPER(expr)
  304.  
  305. VARIABLE(var)
  306.  
  307. WAIT(10ths second)
  308.  
  309. WHILE(expr)
  310.  
  311. ASSIGN(var;expr)
  312.  
  313. Use ASSIGN to assign the value returned by expr to the global variable var. You do not need to enclose the expression in quotes.
  314.  
  315. Expressions are evaluated, and the result is assigned to the variable.
  316.  
  317. Non-numeric characters and expressions that cannot be evaluated numerically are treated as strings.
  318.  
  319. After a value has been assigned to a variable, the variable command VARIABLE(var) can be placed anywhere you would normally place the variable contents. To erase a variable (remove it from memory), leave the expr argument empty. For example, you could use the command ASSIGN(Fred;) to erase a variable named Fred. When you erase a variable, it no longer "exists." For information, see IFEXISTS(var).
  320.  
  321. To assign a local variable, see ASSIGNLOCAL(var;expr).
  322.  
  323. In the following example, variable Fred is first assigned a value, then an expression, then a string.
  324.  
  325.  
  326.  
  327. CODES(
  328.  
  329. ASSIGN(Fred;3)
  330.  
  331.     Assign 3 to variable Fred.
  332.  
  333. ASSIGN(Fred;VARIABLE(Fred)*2)
  334.  
  335.     Multiply old value of variable Fred by 2; assign the result (6) as the new value of variable Fred.
  336.  
  337. ASSIGN(Fred;WordPerfect)
  338.  
  339.     Assign the string "WordPerfect" to variable Fred.
  340.  
  341. VARIABLE(Fred)
  342.  
  343.     Return the value of the variable to the document.
  344.  
  345. )
  346.  
  347. BEEP
  348.  
  349. Use BEEP to cause your computer to beep. This command is often useful in combination with CHAR, KEYBOARD, PROMPT, STATUSPROMPT, and GETSTRING, which prompt the user. You can also use it to signal various points of the merge, such as the end of a lengthy process.
  350.  
  351. The following example sounds a beep at each keyboard pause. The user enters the requested information, then click Continue on the Merge feature bar or presses ALT + ENTER (ENDFIELD) to continue to the next prompt.
  352.  
  353.  
  354.  
  355.         MEMO
  356.  
  357.  
  358.  
  359. To:        BEEP KEYBOARD(Enter To information)
  360.  
  361. From:    BEEP KEYBOARD(Enter From information)
  362.  
  363. Date:    DATE
  364.  
  365. Subject:     BEEP KEYBOARD(Enter Subject information)
  366.  
  367. BREAK
  368.  
  369. Use BREAK to exit from a loop before it would normally end. The location of the command and the type of file it is in determine how it functions.
  370.  
  371. The rules that govern how BREAK functions are listed below:
  372.  
  373. Each of the following rules assumes that the previous rules do not hold.
  374.  
  375.   If BREAK is encountered within a FORNEXT or WHILE structure, execution moves to the end of the structure (just after the ENDFOR or ENDWHILE). If these structures are nested, execution moves after the ENDFOR or ENDWHILE command of the current level.
  376.   
  377.   If BREAK is encountered in a nested file, execution returns to the parent file.
  378.   
  379.   If BREAK is encountered in a form file, the merge moves to the top of the form file and continues with the next data record.
  380.   
  381.   If BREAK is encountered in a data file, the merge is terminated.
  382.   
  383. The following example uses BREAK to exit an infinite loop when the correct number is guessed.
  384.  
  385.  
  386.  
  387. CODES(
  388.  
  389. ASSIGN(Actual Number;SUBSTR(SYSTEM(random);3;1))
  390.  
  391. WHILE(1)
  392.  
  393. CHAR(Guess;Guess a number between 0 - 9?;Guessing Game)
  394.  
  395. IF(VARIABLE(Guess)=VARIABLE(Actual Number))
  396.  
  397.     BEEP
  398.  
  399.     PROMPT(Correct, the number was VARIABLE(Actual Number))
  400.  
  401.     WAIT(30)
  402.  
  403.     BREAK
  404.  
  405. ELSE
  406.  
  407.     PROMPT(Sorry, the number wasn't VARIABLE(Guess))
  408.  
  409.     WAIT(10)
  410.  
  411. ENDIF
  412.  
  413. ENDWHILE
  414.  
  415. )
  416.  
  417. CALL(label)
  418.  
  419. Use CALL to transfer execution to the label subroutine. When execution of the subroutine is completed (when a RETURN is encountered in the subroutine), execution returns to the command following CALL. For more information about subroutines and labels, see Levels.
  420.  
  421. The example below is a form file that creates a data file. The Info subroutine is called to get the information for each record.
  422.  
  423. GETSTRING prompts the user to enter information and assigns the information to a variable. MRGCMND places the necessary merge codes into the data file being created.
  424.  
  425. When no name is entered for variable name, that variable is erased.
  426.  
  427. IFEXISTS then returns a false (0), and QUIT is executed, ending the merge.
  428.  
  429.  
  430.  
  431. CODES(
  432.  
  433. MRGCMND(FIELDNAMES(Name;Address;City;State;ZIP)ENDRECORD ====================================
  434.  
  435. )
  436.  
  437. WHILE(1)
  438.  
  439.     CALL(Info)
  440.  
  441.     VARIABLE(name)MRGCMND(ENDFIELD)
  442.  
  443.     VARIABLE(address)MRGCMND(ENDFIELD)
  444.  
  445.     VARIABLE(city)MRGCMND(ENDFIELD)
  446.  
  447.     VARIABLE(state)MRGCMND(ENDFIELD)
  448.  
  449.     VARIABLE(zip)MRGCMND(ENDFIELD)
  450.  
  451.     MRGCMND(ENDRECORD)
  452.  
  453. ====================================
  454.  
  455. ENDWHILE
  456.  
  457. LABEL(Info)
  458.  
  459. GETSTRING(name;Enter Name or choose Cancel to Quit;Name)
  460.  
  461. IFEXISTS(name)
  462.  
  463. ELSE
  464.  
  465. QUIT
  466.  
  467. ENDIF
  468.  
  469. GETSTRING(address;Enter Address;Address)
  470.  
  471. GETSTRING(city;Enter City;City)
  472.  
  473. GETSTRING(state;Enter State;State)
  474.  
  475. GETSTRING(zip;Enter ZIP Code;ZIP Code)
  476.  
  477. RETURN
  478.  
  479. )
  480.  
  481. CANCELOFF
  482.  
  483. Use CANCELOFF to stop the ESC key from performing its normal function. CANCELOFF is useful to prevent a user from stopping a merge by pressing ESC.
  484.  
  485.  
  486.  
  487. CANCELOFF
  488.  
  489.   
  490.   
  491.   (During this part of the merge, pressing Cancel does not end the merge.)
  492.   
  493.   
  494.   
  495. CANCELON
  496.  
  497.   
  498.   
  499.   (During this part of the merge, pressing Cancel does not end the merge.)
  500.   
  501.   
  502.   
  503. CANCELON
  504.  
  505. Use CANCELON to enable the ESC key after it has been disabled with the CANCELOFF command.
  506.  
  507. For an example of CANCELON, see CANCELOFF.
  508.  
  509. CAPS(expr)
  510.  
  511. Use CAPS to capitalize the first character of each word in the returned expression expr.
  512.  
  513. To change all letters in a returned expression to uppercase or lowercase, see TOUPPER or TOLOWER. To capitalize just the first word, see FIRSTCAP.
  514.  
  515. In the example below, CAPS capitalizes the first letter of each word in the name, address, and city variables. TOUPPER capitalizes both letters of the state abbreviation. FIRSTCAP capitalizes the first letter of the first word in the comments string. TOLOWER ensures that the merge will continue if either an uppercase or a lowercase "y" is assigned to VARIABLE(char).
  516.  
  517.  
  518.  
  519. CODES(
  520.  
  521. LABEL(info)
  522.  
  523. GETSTRING(name;Enter Name;Name)
  524.  
  525. ASSIGN(name;CAPS(VARIABLE(name)))
  526.  
  527. GETSTRING(address;Enter Address;Address)
  528.  
  529. ASSIGN(address;CAPS(VARIABLE(address)))
  530.  
  531. GETSTRING(city;Enter City;City)
  532.  
  533. ASSIGN(city;CAPS(VARIABLE(city)))
  534.  
  535. GETSTRING(state;Enter state abbreviation;State)
  536.  
  537. ASSIGN(state;TOUPPER(VARIABLE(state)))
  538.  
  539. GETSTRING(zip;Enter ZIP code;ZIP)
  540.  
  541. GETSTRING(comments;Enter comments;Additional Comments)
  542.  
  543. ASSIGN(comments;FIRSTCAP(VARIABLE(comments)))
  544.  
  545. VARIABLE(name)
  546.  
  547. VARIABLE(address)
  548.  
  549. VARIABLE(city) VARIABLE(state) VARIABLE(zip)
  550.  
  551. VARIABLE(comments)
  552.  
  553. ====================================
  554.  
  555. CODES(
  556.  
  557. CHAR(char;Do Another Record?;Continue (Y/N)?)
  558.  
  559. IF(TOLOWER(VARIABLE(char)) = y)
  560.  
  561.     GO(info)
  562.  
  563. ENDIF
  564.  
  565. )
  566.  
  567. CASEOF(expr[;...;expr])
  568.  
  569. Use CASEOF when using the SWITCH command. When you use CASEOF, you can enter multiple merge expressions within the parentheses.
  570.  
  571. For examples of CASEOF, see SWITCH and FORNEXT.
  572.  
  573. CHAINDATA(filename)
  574.  
  575. Use CHAINDATA to begin using records from the named data file, when the end of the current data file is reached. This command is especially useful if you have broken a large data file into several smaller files. If you insert CHAINDATA in the smaller data files, they will act like one data file.
  576.  
  577. The following example shows how a large data file has been broken into two smaller files. When you specify the first small file as the data file in a merge, the records of the second small file will be used as soon as those in the first small file are completed.
  578.  
  579. First Small File:
  580.  
  581.  
  582.  
  583. FIELDNAMES(name;status) ENDRECORD
  584.  
  585. ====================================
  586.  
  587. PROCESSON CHAINDATA(file2)PROCESSOFF COMMENT(
  588.  
  589.     The PROCESS commands ensure that the CHAINDATA command executes.
  590.  
  591.     The merge stores the CHAINDATA command and filename, then executes it
  592.  
  593.     when the current data file has ended.)
  594.  
  595. JoseENDFIELD
  596.  
  597. StaffENDFIELD
  598.  
  599. ENDRECORD
  600.  
  601. ====================================
  602.  
  603.   
  604.   
  605.   (additional records)
  606.   
  607.   
  608.   
  609. ====================================
  610.  
  611. BarbaraENDFIELD
  612.  
  613. ProfessionalENDFIELD
  614.  
  615. ENDRECORD
  616.  
  617.  
  618.  
  619. Second Small File (named FILE2 in the default directory):
  620.  
  621.  
  622.  
  623. FIELDNAMES(name;status)
  624.  
  625. ENDRECORD
  626.  
  627. ====================================
  628.  
  629. JulieENDFIELD
  630.  
  631. Part-timeENDFIELD
  632.  
  633. ENDRECORD
  634.  
  635. ====================================
  636.  
  637.   
  638.   
  639.   (additional records)
  640.   
  641.   
  642.   
  643. ====================================
  644.  
  645. ShojiENDFIELD
  646.  
  647. Leave of AbsenceENDFIELD
  648.  
  649. ENDRECORD
  650.  
  651. ====================================
  652.  
  653. CHAINFORM(filename)
  654.  
  655. Use CHAINFORM to continue the merge with an additional form file after all records have been merged with the current form file.
  656.  
  657. The following example uses CHAINFORM to merge an envelope form file with the current data file.
  658.  
  659.  
  660.  
  661. CHAINFORM(envelope.frm)
  662.  
  663.   
  664.   
  665.   (body of form file)
  666.   
  667.   
  668.   
  669. CHAINMACRO(macroname)
  670.  
  671. Use CHAINMACRO to start the named macro at the end of the merge, if the merge terminates normally. You can place CHAINMACRO anywhere in the form file.
  672.  
  673. Only the last macro chained during the merge is executed.
  674.  
  675. In the following example, the chained macro print.wcm executes when the merge is complete.
  676.  
  677.  
  678.  
  679. CHAINMACRO(print)
  680.  
  681. COMMENT(Chain the macro PRINT.WCM when the merge is complete.)
  682.  
  683.  
  684.  
  685. DATE
  686.  
  687. Dear FIELD(Name),
  688.  
  689.   
  690.   
  691.   (rest of the letter)
  692.   
  693.   
  694.   
  695. Sincerely,
  696.  
  697.  
  698.  
  699. Chris Smith
  700.  
  701. CHAR(var[;prompt][;title])
  702.  
  703. Use CHAR to prompt the user to input a single character. CHAR prompts you with a message and waits until you press a single key.
  704.  
  705. The pressed key is assigned to the specified variable var. Prompt is the information displayed in the dialog box telling the user what to do.
  706.  
  707. Title is the title of the dialog box created during the merge.
  708.  
  709. For an example of CHAR, see CTON.
  710.  
  711. CODES(merge codes)
  712.  
  713. Use CODES to enter merge codes and have the merge ignore any formatting or text you might add. The merge carries out all the merge commands inside the CODES parentheses but ignores any text or formatting (such as hard returns). To enter text or formatting inside the CODES parentheses, use the INSERT command.
  714.  
  715. The following would occur in a form file. When merging with a data file, the example pauses the merge at each record and lets you choose which records you want to merge.
  716.  
  717.  
  718.  
  719. CODES(
  720.  
  721. LABEL(top)
  722.  
  723. ASSIGN(field;FIELD(1))
  724.  
  725. EMBEDMACRO(
  726.  
  727.     PERSIST(fld)
  728.  
  729.     PROMPT("Which name would you like to merge? ";" OK to merge "+field+"?";2)
  730.  
  731.     PAUSE
  732.  
  733.     ENDPROMPT
  734.  
  735. )
  736.  
  737. IF(VARIABLE(fld)=2)
  738.  
  739.     INSERT(FIELD(1))
  740.  
  741.     INSERT(FIELD(2))
  742.  
  743.     INSERT(FIELD(3))
  744.  
  745. ====================================
  746.  
  747. ENDIF
  748.  
  749. NEXTRECORD
  750.  
  751. GO(top)
  752.  
  753. )
  754.  
  755.  
  756.  
  757. For another example of CODES, see CTON.
  758.  
  759. COMMENT(comment)
  760.  
  761. Use COMMENT to include comments that will make the merge easier to understand. Merge ignores everything between the COMMENT parentheses.
  762.  
  763. For an example of COMMENT, see CTON.
  764.  
  765. CONTINUE
  766.  
  767. Use CONTINUE at the end of a CASEOF statement to execute the commands in the next CASEOF statement.
  768.  
  769. For examples of CONTINUE, see SWITCH and FORNEXT.
  770.  
  771. CTON(character)
  772.  
  773. Use CTON (Character to number) to convert a character (any character in the WordPerfect character sets) to a unique number (its WordPerfect "key value"). CTON performs the inverse (opposite) function of NTOC. You can use the key value to calculate the WordPerfect character set value.
  774.  
  775. To calculate the character set value for a given character
  776.  
  777. 1     Use CTON to obtain the key value.
  778.  
  779. 2     Divide the key value by 256.
  780.  
  781. The quotient is the number of the WordPerfect character set (0-12).
  782.  
  783. The remainder is the character number in the character set (0-255).
  784.  
  785. The following example calculates the character set value for a character. Because all the variables are local, this file could be nested within another file and would not change any of the original file's variables, even if they have the same name. The comments in the first part of this merge do not need to be in a COMMENT command, because they are within the CODES command. The final comment must be in a COMMENT command, or it will be inserted in the merged document.
  786.  
  787.  
  788.  
  789. CODES(
  790.  
  791. ASSIGNLOCAL(char;0)
  792.  
  793.     Initialize a local variable named char.
  794.  
  795. CHAR(char;Type a character;Display Character Set Value)
  796.  
  797.     Assign input to the variable char.
  798.  
  799. ASSIGNLOCAL(set;CTON(VARIABLE(char))/256)
  800.  
  801.     Assign quotient to a variable named set.
  802.  
  803. ASSIGNLOCAL(num;CTON(VARIABLE(char))%256)
  804.  
  805.     Assign remainder to a variable named num.
  806.  
  807. )
  808.  
  809. VARIABLE(set),VARIABLE(num)
  810.  
  811. COMMENT(Write out the character set value.)
  812.  
  813. DATE
  814.  
  815. Use DATE to insert the current date in merged documents, as formatted in the Date format feature. The merged file will contain the current date as indicated by your computer's internal clock.
  816.  
  817. For an example of DATE, see BEEP.
  818.  
  819. DEFAULT
  820.  
  821. Use DEFAULT with the SWITCH command to cover all cases not covered by CASEOF. When the expression being tested is different from all the CASEOF expressions, the merge executes DEFAULT.
  822.  
  823. For examples of DEFAULT, see SWITCH and FORNEXT.
  824.  
  825. DISPLAYSTOP
  826.  
  827. Use DISPLAYSTOP to stop the display of text after a KEYBOARD command. For example, after a KEYBOARD command, the merge displays as many as 1000 characters ahead. DISPLAYSTOP placed in text after KEYBOARD stops the text from displaying from that point on.
  828.  
  829.  
  830.  
  831. DATE
  832.  
  833. FIELD(name)
  834.  
  835. FIELD(address)
  836.  
  837. FIELD(city)
  838.  
  839. Dear FIELD(name):
  840.  
  841. It has come to our attention that your bill has not been paid. Please send us $KEYBOARD(Enter how much they owe us-Press ALT+ENTER or choose Continue when done), which is the balance of your unpaid account.DISPLAYSTOP
  842.  
  843. If the balance of your account is not paid in KEYBOARD(Enter how many days-Press ALT + ENTER or choose Continue when done) days, we will be forced to take legal action.DISPLAYSTOP
  844.  
  845. If you have already made arrangements to settle your account, please disregard this notice.
  846.  
  847. The rest of the letter after DISPLAYSTOP does not display on the screen while the user is prompted to type information at the keyboard.
  848.  
  849. This removes distracting information from the screen, so users can focus their attention on the area where they are to enter information.
  850.  
  851. DOCUMENT(filename)
  852.  
  853. Use DOCUMENT to insert the named document into the merged document at the DOCUMENT command. The document is not processed as a merge file, so any merge commands in the inserted document are included in the file but not executed. This command is commonly used for inserting variable paragraphs in contracts and similar documents (often called document assembly) or for building a form or data file.
  854.  
  855. In the following example, DOCUMENT inserts the document called oneroom.mrg in the merged document if the variable rooms is equal to 1, or it inserts the document tworooms.mrg if the variable rooms is not equal to 1.
  856.  
  857.  
  858.  
  859. CODES(
  860.  
  861. CHAR(rooms;Enter the number of rooms (1 or 2); Number of Rooms)
  862.  
  863. IF(VARIABLE(rooms)=1)
  864.  
  865.     DOCUMENT(c:\mrgfiles\oneroom.mrg)
  866.  
  867. ELSE
  868.  
  869.     DOCUMENT(c:\mrgfiles\tworooms.mrg)
  870.  
  871. ENDIF
  872.  
  873. )
  874.  
  875. ELSE
  876.  
  877. Use ELSE with IF, IFBLANK, IFEXISTS, IFNOTBLANK, and ENDIF. ELSE marks the beginning of the commands that execute should the IF value be zero (false).
  878.  
  879. ELSE is not a required part of an IF statement. It should be used when there are certain steps that need to be performed only when the IF value is zero (false).
  880.  
  881. Commands that appear after ENDIF execute whether or not the IF value is true.
  882.  
  883. For an example of ELSE, see DOCUMENT.
  884.  
  885. EMBEDMACRO(macro statements)
  886.  
  887. Use EMBEDMACRO to embed macro commands within a merge. You can enter any macro command inside the EMBEDMACRO parentheses. The macro commands are compiled the first time they are encountered during the merge.
  888.  
  889. For an example of EMBEDMACRO, see CODES.
  890.  
  891. ENDFIELD
  892.  
  893. Use ENDFIELD to signal the end of a field in a data file. A hard return [HRt] is automatically inserted with this command to make the file easier to read.
  894.  
  895. When you insert this command, the number of the field where the cursor is currently located displays at the bottom of the window. If you use FIELDNAMES, the name of the field appears instead of the number.
  896.  
  897. Records in the following data file have three fields:
  898.  
  899.  
  900.  
  901. International ExportingENDFIELD
  902.  
  903. (801) 555-4421ENDFIELD
  904.  
  905. George WileyENDFIELD
  906.  
  907. ENDRECORD
  908.  
  909. ====================================
  910.  
  911. Tradewinds, Inc.ENDFIELD
  912.  
  913. (409) 555-3567ENDFIELD
  914.  
  915. Susan EscherENDFIELD
  916.  
  917. ENDRECORD
  918.  
  919. ====================================
  920.  
  921. ENDFOR
  922.  
  923. Use ENDFOR to signal the end of FORNEXT and FOREACH loops.
  924.  
  925. For an example of ENDFOR, see FORNEXT.
  926.  
  927. ENDIF
  928.  
  929. Use ENDIF to mark the end of an IF structure. ENDIF is used with IF, IFBLANK, IFEXISTS, IFNOTBLANK, and ELSE.
  930.  
  931. For an example of ENDIF, see DOCUMENT.
  932.  
  933. ENDRECORD
  934.  
  935. Use ENDRECORD to signal the end of a record in a data file. A hard page break is inserted automatically with this command to make the file easier to read.
  936.  
  937. When you insert this command, the number of the field where the cursor is currently located displays at the bottom of the window. If you use FIELDNAMES, the name of the field appears instead of the number.
  938.  
  939. For examples of ENDRECORD, see ENDFIELD and FIELDNAMES.
  940.  
  941. ENDSWITCH
  942.  
  943. Use ENDSWITCH to end a SWITCH statement.
  944.  
  945. For an example of ENDSWITCH, see SWITCH.
  946.  
  947. ENDWHILE
  948.  
  949. Use ENDWHILE to signal the end of a WHILE loop.
  950.  
  951. For an example of ENDWHILE, see NEXTRECORD.
  952.  
  953. FIELD(field)
  954.  
  955. Use FIELD to insert the contents of the named (or numbered) field in the merged document or in another merge command.
  956.  
  957. In the following example, the contents of the name and address fields are inserted in the letter.
  958.  
  959.  
  960.  
  961. FIELD(name)
  962.  
  963. FIELD(address)
  964.  
  965. Dear FIELD(name):
  966.  
  967.  
  968.  
  969. For additional examples of FIELD, see DISPLAYSTOP.
  970.  
  971. FIELDNAMES(name1;...;nameN)
  972.  
  973. Use FIELDNAMES to declare the names and order of the fields in a data file. Using this command in the data file allows you to reference the fields by name in a form file, which is usually easier than remembering the order of the fields and referencing them by number.
  974.  
  975. WordPerfect places FIELDNAMES at the top of the data file. It must be located at the top of the file to work correctly. If records have more fields than those declared in FIELDNAMES, additional fields are numbered. When initially inserted, the command and field names are all on one line. You may find it easier to read if you put each field name on a separate line, as in the example below. A hard page code [HPg] is automatically inserted when you insert ENDRECORD.
  976.  
  977. After you insert this command, the name or number of the field where the cursor is currently located displays on the status bar at the bottom of the window.
  978.  
  979. In the following example, the first three fields of each record are named using FIELDNAMES. The additional fields are not named and are therefore numbered Field 4, Field 5, and so on.
  980.  
  981.  
  982.  
  983. FIELDNAMES(
  984.  
  985. company;
  986.  
  987. phone;
  988.  
  989. contact;
  990.  
  991. )ENDRECORD
  992.  
  993. ====================================
  994.  
  995. International ExportingENDFIELD
  996.  
  997. (801) 555-4421ENDFIELD
  998.  
  999. George WileyENDFIELD
  1000.  
  1001. FurnitureENDFIELD
  1002.  
  1003. 45ENDFIELD
  1004.  
  1005. $1.5 millionENDFIELD
  1006.  
  1007. ENDRECORD
  1008.  
  1009. ====================================
  1010.  
  1011. Tradewinds, Inc.ENDFIELD
  1012.  
  1013. (409) 555-3567ENDFIELD
  1014.  
  1015. Susan EscherENDFIELD
  1016.  
  1017. MemorabiliaENDFIELD
  1018.  
  1019. 200ENDFIELD
  1020.  
  1021. $2.0 millionENDFIELD
  1022.  
  1023. ENDRECORD
  1024.  
  1025. ====================================
  1026.  
  1027.  
  1028.  
  1029. For another example of FIELDNAMES, see CHAINDATA.
  1030.  
  1031. FIRSTCAP(expr)
  1032.  
  1033. Use FIRSTCAP to capitalize the first letter of the first word in the returned expression expr.
  1034.  
  1035. For an example of FIRSTCAP, see CAPS.
  1036.  
  1037. FOREACH(var;expr1;...;exprN)
  1038.  
  1039. Use FOREACH to assign a list of items to one variable var. The merge then executes the subsequent commands for each expr listed in FOREACH, changing var to the next value at the end of each loop.
  1040.  
  1041. For example, the following codes assign different days of the week to the variable weekday until it matches the field day.
  1042.  
  1043.  
  1044.  
  1045. FOREACH(weekday;Monday;Tuesday;Wednesday;Thursday;Friday)
  1046.  
  1047. IF(VARIABLE(weekday)=FIELD(day))
  1048.  
  1049.     BREAK
  1050.  
  1051. ENDIF
  1052.  
  1053. ENDFOR
  1054.  
  1055. FORNEXT(var;start;stop[;step])
  1056.  
  1057. Use FORNEXT to execute a series of commands a certain number of times. The commands between FORNEXT and ENDFOR are executed once for each value of var between start and stop inclusive, as incremented by step.
  1058.  
  1059. The start, stop, and step values can be entered in the command as expressions, variables, or other commands. Each expression, variable, or command is evaluated, and the resulting value is assigned to the variable. The step value is optional; its default value is 1 (or -1, if stop is less than start).
  1060.  
  1061. In any FORNEXT loop, ENDFOR must be used to determine the end of the series of commands included in the loop. ENDFOR sends execution to the top of the loop for the next iteration. You can also use NEXT to send execution to the next iteration, but you must still include ENDFOR to mark the end of the loop.
  1062.  
  1063. FORNEXT initializes the variable with the start value. If the variable has not been assigned, it is defined as a local variable. You do not need to pre-assign the variable. Each subsequent time FORNEXT is executed (at the top of the loop), the variable is incremented by the step value.
  1064.  
  1065. The example below uses a FORNEXT loop to apply a SWITCH statement once for each character in the sentence that is entered.
  1066.  
  1067.  
  1068.  
  1069. CODES(
  1070.  
  1071. GETSTRING(sentence;Type a sentence;Sentence To Be Evaluated)
  1072.  
  1073. ASSIGN(vowels;0)
  1074.  
  1075. ASSIGN(consonants;0)
  1076.  
  1077. ASSIGN(misc;0)
  1078.  
  1079. FORNEXT(i;1;STRLEN(VARIABLE(sentence));)
  1080.  
  1081.     SWITCH(TOLOWER(SUBSTR(VARIABLE(sentence);VARIABLE(i);1)))
  1082.  
  1083.     CASEOF(a;e;i;o;u)
  1084.  
  1085.         ASSIGN(vowels;VARIABLE(vowels)+1)
  1086.  
  1087.     CASEOF(b;c;d)
  1088.  
  1089.         CONTINUE
  1090.  
  1091.     CASEOF(f;g;h;)
  1092.  
  1093.         CONTINUE
  1094.  
  1095.     CASEOF(j;k;l;m;n)
  1096.  
  1097.         CONTINUE
  1098.  
  1099.     CASEOF(p;q;r;s;t)
  1100.  
  1101.         CONTINUE
  1102.  
  1103.     CASEOF(v;w;x;y;z)
  1104.  
  1105.         ASSIGN(consonants;VARIABLE(consonants)+1)
  1106.  
  1107.     DEFAULT
  1108.  
  1109.         ASSIGN(misc;VARIABLE(misc)+1)
  1110.  
  1111.     ENDSWITCH
  1112.  
  1113. ENDFOR
  1114.  
  1115. )
  1116.  
  1117. There were:
  1118.  
  1119. VARIABLE(vowels) vowels,
  1120.  
  1121. VARIABLE(consonants) consonants, and
  1122.  
  1123. VARIABLE(misc) other characters.
  1124.  
  1125. GETSTRING(var[;prompt][;title])
  1126.  
  1127. Use GETSTRING to prompt the user by displaying a dialog box.
  1128.  
  1129. Information returned by the dialog box is assigned to the variable var.
  1130.  
  1131. Prompt is the information displayed in the dialog box telling the user what to do. Title is the title of the dialog box created during the merge.
  1132.  
  1133. For an example of GETSTRING, see CAPS.
  1134.  
  1135. GO(label)
  1136.  
  1137. Use GO to transfer execution to the location in the merge file indicated by label. It is used in conjunction with LABEL, which marks the place to which execution is transferred.
  1138.  
  1139. GO is useful when you want to skip a part of your merge or transfer control to another part based on a condition. Unlike CALL, GO does not require the merge to return to that point of execution.
  1140.  
  1141. For an example of GO, see CAPS.
  1142.  
  1143. IF(expr)
  1144.  
  1145. Use IF to execute a set of commands only if a certain condition exists.
  1146.  
  1147. If the condition exists (expr is evaluated to be true), the commands between the IF and ENDIF are executed. If an ELSE is included, the commands between the IF and ELSE are executed if the expression is true; otherwise, the commands between the ELSE and ENDIF are executed.
  1148.  
  1149. The expr argument is usually a logical expression. An expression is true if it is evaluated as a non-zero number. For example, when the expression 4=4 is evaluated, the result is -1 (which corresponds to true). The value is false if it results in a 0 or contains nothing at all.
  1150.  
  1151. An IF statement always begins with IF and ends with ENDIF. If you want certain commands to execute only when the value is not true, use ELSE.
  1152.  
  1153. For an example of IF, see DOCUMENT.
  1154.  
  1155. IFBLANK(field)
  1156.  
  1157. IFBLANK(field) Use IFBLANK to execute a set of commands if the indicated field is blank. Be sure to end the set of commands to be executed with an ENDIF command. See also IFNOTBLANK.
  1158.  
  1159. In the following example, the data file records have a Title field and a Name field. The merge determines if the Title field of the current record is blank. If it is blank, only the name is inserted in the merged document. Otherwise, the merge inserts the title before the name.
  1160.  
  1161.  
  1162.  
  1163. CODES(
  1164.  
  1165. IFBLANK(title)
  1166.  
  1167.         If the Title field is blank in this record,
  1168.  
  1169.     INSERT(FIELD(name))
  1170.  
  1171.         Write out just the Name.
  1172.  
  1173.     ELSE
  1174.  
  1175.         Otherwise,
  1176.  
  1177.     INSERT(FIELD(title) FIELD(name))
  1178.  
  1179.         Write the Title before the Name.
  1180.  
  1181. ENDIF
  1182.  
  1183.         End of IFBLANK statement.
  1184.  
  1185. )
  1186.  
  1187. IFEXISTS(var)
  1188.  
  1189. Use IFEXISTS to check if the indicated variable has been defined. If it has, the commands following IFEXISTS are executed. Like other IF statements, IFEXISTS requires an ENDIF and can use an ELSE command.
  1190.  
  1191. The following commands could be placed at the end of any form file.
  1192.  
  1193. They cancel the merge if any key is pressed.
  1194.  
  1195.  
  1196.  
  1197. LOOK(Key)
  1198.  
  1199. IFEXISTS(Key)
  1200.  
  1201.     STOP
  1202.  
  1203. ENDIF
  1204.  
  1205. IFNOTBLANK(field)
  1206.  
  1207. Use IFNOTBLANK to execute a set of commands if the indicated field is not blank. Be sure to end the set of commands to be executed with an ENDIF command. See also IFBLANK.
  1208.  
  1209. In the following example, the data merge file records have a Title field and a Name field. The merge determines if the Title field of the current record is blank. If it is not, the title is inserted before the name. Otherwise, the merge inserts only the name.
  1210.  
  1211.  
  1212.  
  1213. CODES(
  1214.  
  1215. IFNOTBLANK(title)
  1216.  
  1217.         If the Title field is not blank in this record,
  1218.  
  1219.     INSERT(FIELD(title) FIELD(name))
  1220.  
  1221.         Write the Title before the Name.
  1222.  
  1223.     ELSE
  1224.  
  1225.         Otherwise,
  1226.  
  1227.     INSERT(FIELD(name))
  1228.  
  1229.         Write out only the Name.
  1230.  
  1231. ENDIF
  1232.  
  1233.         End of IFNOTBLANK statement.
  1234.  
  1235. )
  1236.  
  1237. INSERT(text)
  1238.  
  1239. Use INSERT to enter text or formatting inside a CODES command.
  1240.  
  1241. For example, the merge will not recognize a hard return inside the CODES parentheses. To make the merge return a hard return, use INSERT, then press hard return.
  1242.  
  1243. For examples of INSERT, see IFNOTBLANK and NESTMACRO(macroname).
  1244.  
  1245. KEYBOARD([prompt])
  1246.  
  1247. Use KEYBOARD to pause an executing merge so the user can enter information from the keyboard. As many as 1,000 characters of the form file are displayed. Merge codes are displayed using the current display setting. The merge continues when you click Continue on the Merge feature bar or press ALT + ENTER (ENDFIELD).
  1248.  
  1249. While an executing merge is paused at KEYBOARD, you can execute QUIT, NEXTRECORD, or STOP from the keyboard.
  1250.  
  1251. In the following example, the KEYBOARD commands pause to let you enter the "From:," "To:," and "Subject:" text as the merge is executed.
  1252.  
  1253.  
  1254.  
  1255.         MEMO
  1256.  
  1257.  
  1258.  
  1259. To:        BEEP KEYBOARD(Enter To information)
  1260.  
  1261. From:    BEEP KEYBOARD(Enter From information)
  1262.  
  1263. Date:    DATE
  1264.  
  1265. Subject:     BEEP KEYBOARD(Enter Subject information)
  1266.  
  1267.  
  1268.  
  1269. If KEYBOARD is executed within another merge command, a dialog box displays with the indicated prompt. You cannot execute commands from the keyboard, but any text entered at the prompt is inserted into the merged document.
  1270.  
  1271. LABEL(label)
  1272.  
  1273. Use LABEL to mark a place in the merge file. Execution can be sent directly to the label from any place in the merge file. CALL and GO are used to send execution to the label.
  1274.  
  1275. The label name distinguishes one label from another. Label names can be as many as 30 characters long, including spaces. Different labels in the same merge file must have different names. If a name is duplicated, the first one is used, and the other is ignored.
  1276.  
  1277. Do not assign a label and local variable the same name, or the merge may not function properly.
  1278.  
  1279. For examples of LABEL, see CALL and CAPS.
  1280.  
  1281. LOOK(var)
  1282.  
  1283. Use LOOK to determine if a key has been pressed. If it has, that key is assigned to the variable; it is not executed. If no key has been pressed, the variable is deleted; execution continues without stopping.
  1284.  
  1285. For an example of LOOK, see IFEXISTS.
  1286.  
  1287. MRGCMND(merge codes)
  1288.  
  1289. Use MRGCMND to insert text, codes, and commands in the document being created by the merge. Any text, codes, or merge commands that appear between the MRGCMND parentheses are sent directly to the merged document without the commands being interpreted or executed.
  1290.  
  1291. For an example of MRGCMND, see CALL.
  1292.  
  1293. NESTDATA(filename)
  1294.  
  1295. Use NESTDATA to interrupt the use of the current data file and switch to another data file during the merge. The parent data file then continues only when the merge on the nested data file has been completed. You can nest data files as many as 10. For information, see Levels.
  1296.  
  1297. If you nest from within one data file to another, be careful to avoid infinite loops. Use CANCEL or BREAK to terminate the loop.
  1298.  
  1299. When you nest a data file, the switch to that file occurs immediately.
  1300.  
  1301. When you chain data files, the switch to the new data file is made when the end of the current data file is reached. For more information, see CHAINDATA.
  1302.  
  1303. For an example of NESTDATA, see NESTFORM.
  1304.  
  1305. NESTFORM(filename)
  1306.  
  1307. Use NESTFORM to turn control of the merge over to another form file. When the commands in the nested file have been executed, control returns to the original form file, where execution resumes after NESTFORM. For information on how to change the data file, see NESTDATA.
  1308.  
  1309. You can nest form files as many as 10. Using NESTFORM without specifying a filename is the same as using SUBSTFORM with the current form filename as the argument. In this case, NESTFORM does not use one of the 10 nest levels. For more information, see Levels.
  1310.  
  1311.  
  1312.  
  1313. FIELD(name),
  1314.  
  1315. It has been a pleasure serving you this year.
  1316.  
  1317. CODES(
  1318.  
  1319. IF(FIELD(balance)!=0)
  1320.  
  1321.     NESTDATA(transact.dat)
  1322.  
  1323.     NESTFORM(invoice.frm)
  1324.  
  1325. ENDIF
  1326.  
  1327. )
  1328.  
  1329. Sincerely,
  1330.  
  1331. NESTMACRO(macroname)
  1332.  
  1333. Use NESTMACRO to execute the named macro during a merge.
  1334.  
  1335. When the macro is finished, the merge continues with the code following NESTMACRO.
  1336.  
  1337. Macros created in earlier versions of WordPerfect (before version 6.x) will need to be converted.
  1338.  
  1339. The following example nests a macro that computes the interest on an account balance.
  1340.  
  1341.  
  1342.  
  1343. CODES(
  1344.  
  1345. ASSIGN(balance;FIELD(balance))
  1346.  
  1347. NESTMACRO(calcint)
  1348.  
  1349. INSERT(Interest on this balance is VARIABLE(interest))
  1350.  
  1351. )
  1352.  
  1353. NEXT
  1354.  
  1355. Use NEXT to execute the next iteration of a FORNEXT, FOREACH, or WHILE loop. Usually, the ENDFOR or ENDWHILE that ends the loop sends execution to the next iteration. However, you can use NEXT to send execution to the next iteration from anywhere within the loop. For example, you may use nested IF statements as part of the loop. Then, when a certain condition is true, execution will skip the rest of the commands in the loop and go to the next iteration. In this case, you would use NEXT at the point where you want the next iteration to begin.
  1356.  
  1357. Even if you use NEXT in a loop, you must still use an ENDFOR or ENDWHILE to mark the end of the loop.
  1358.  
  1359. The following merge writes **********@@@@@.
  1360.  
  1361.  
  1362.  
  1363. CODES(
  1364.  
  1365. FORNEXT(i;1;15;1)
  1366.  
  1367.         Repeat the loop 15 times, starting at 1, ending at 15, in
  1368.  
  1369.         increments of 1.
  1370.  
  1371. IF(VARIABLE(i)10)
  1372.  
  1373.         If variable i is greater than 10,
  1374.  
  1375.     INSERT(@)
  1376.  
  1377.         write an @,
  1378.  
  1379.     NEXT
  1380.  
  1381.         and skip to the next iteration of this FORNEXT loop.
  1382.  
  1383.     ENDIF
  1384.  
  1385. INSERT(*)
  1386.  
  1387.         Write an * each time the loop is completed.
  1388.  
  1389. ENDFOR
  1390.  
  1391. )
  1392.  
  1393. NEXTRECORD
  1394.  
  1395. Use NEXTRECORD to move the record pointer in the data file to the next record. If it does not find the next record, it ends the merge or returns the merge to the previous data file if the data file was nested.
  1396.  
  1397. While an executing merge is paused at KEYBOARD, you can execute NEXTRECORD from the keyboard.
  1398.  
  1399. In this example, the data file is searched until the variable company name matches the company field in the data file. When a match is found, the contents of the amount field for that record in the data file are written to the merged document.
  1400.  
  1401.  
  1402.  
  1403. CODES(
  1404.  
  1405. WHILE(VARIABLE(Company Name)!=FIELD(Company))
  1406.  
  1407.     NEXTRECORD
  1408.  
  1409. ENDWHILE
  1410.  
  1411. )
  1412.  
  1413. FIELD(Amount)
  1414.  
  1415. NTOC(number)
  1416.  
  1417. Use NTOC (Number to character) to convert a WordPerfect key value or character set number to its character equivalent. It performs the inverse function of CTON. For example, the NTOC of 294 is ╟.
  1418.  
  1419. To calculate the key value for a given character set value
  1420.  
  1421.   Multiply the character set number by 256, then add the number of the character.
  1422.   
  1423. For example, "╟" is character number 38 in Character Set 1.
  1424.  
  1425. Multiply 256 times 1 (256), then add 38 (294). The NTOC of 294 is ╟.
  1426.  
  1427. NTOC will return nothing if you enter a number that is not equivalent to a character.
  1428.  
  1429. The following example prompts for a number, then returns the character equivalent.
  1430.  
  1431.  
  1432.  
  1433. GETSTRING(num;Enter a key value number;)
  1434.  
  1435. NTOC(VARIABLE(num))
  1436.  
  1437. ONCANCEL(action)
  1438.  
  1439. Use ONCANCEL to specify what the merge does if you press ESC (Cancel) or if a RETURNCANCEL has been returned by a subroutine, a nested macro, or a nested merge. When a Cancel occurs, the merge performs the default action (STOP) if it has not already encountered the ONCANCEL command. For this reason, it is a good idea to place the command before a Cancel can occur, otherwise execution will terminate when ESC is pressed. If no action is specified in ONCANCEL, the cancel is ignored, and execution continues as if there had been no cancel.
  1440.  
  1441. Valid actions available with this command are:
  1442.  
  1443.   BREAK
  1444.   
  1445.   CALL
  1446.   
  1447.   GO
  1448.   
  1449.   QUIT
  1450.   
  1451.   RETURN
  1452.   
  1453.   RETURNCANCEL
  1454.   
  1455.   RETURNERROR
  1456.   
  1457.   STOP
  1458.   
  1459. When ESC is pressed, the last ONCANCEL command encountered in the file is executed.
  1460.  
  1461. ONCANCEL is local to the file in which it is encountered. It cannot be used from other files. For example, a data file cannot use ONCANCEL from a form file.
  1462.  
  1463. In the following example, if you press ESC during the merge, the end subroutine is executed.
  1464.  
  1465.  
  1466.  
  1467. CODES(
  1468.  
  1469. ONCANCEL(GO(end))
  1470.  
  1471.     If ESC is pressed during the merge, execute the End
  1472.  
  1473.     subroutine.
  1474.  
  1475.   
  1476.   
  1477.   (commands in form file)
  1478.   
  1479.   
  1480.   
  1481. STOP
  1482.  
  1483. LABEL(end)
  1484.  
  1485.     Beginning of End subroutine.
  1486.  
  1487. PROMPT(Merge canceled prematurely.)
  1488.  
  1489.     Send notification message.
  1490.  
  1491. WAIT(40)
  1492.  
  1493.     Display message for 4 seconds.
  1494.  
  1495. STOP
  1496.  
  1497.     Terminate execution.
  1498.  
  1499. )
  1500.  
  1501.  
  1502.  
  1503. For another example of ONCANCEL, see RETURNCANCEL.
  1504.  
  1505. ONERROR(action)
  1506.  
  1507. Use ONERROR to tell WordPerfect what to do if an error is detected in merge execution or if a RETURNERROR has been returned by a subroutine or nested macro or merge.
  1508.  
  1509. Inserting ONERROR without an action causes the merge to ignore the error and continue execution when possible.
  1510.  
  1511. The errors that can be trapped with this command are:
  1512.  
  1513.   File not found
  1514.   
  1515.   Print queue errors
  1516.   
  1517.   End of file condition returned by a NEXTRECORD
  1518.   
  1519. If you chain a file that does not exist or is not found, the error condition is not generated until the merge tries to execute the chained file (that is, at the end of the current merge file). For more information, see also CHAINDATA, CHAINFORM(filename), and CHAINMACRO.
  1520.  
  1521. The default action is STOP. For a list of other possible actions, see ONCANCEL.
  1522.  
  1523. ONERROR is local to the file in which it is encountered. It cannot be seen from other files. For example, a data file cannot use ONERROR from a form file.
  1524.  
  1525. In the following example, a new form file is nested. ONERROR specifies that subroutine error be executed if the file is not found when the merge tries to nest it.
  1526.  
  1527.  
  1528.  
  1529. CODES( ONERROR(GO(error))
  1530.  
  1531.     If an error is generated, execute the Error subroutine.
  1532.  
  1533.   
  1534.   
  1535.   (more merge commands)
  1536.   
  1537.   
  1538.   
  1539. NESTFORM(invoice.frm)
  1540.  
  1541.   
  1542.   
  1543.   (more merge commands)
  1544.   
  1545.   
  1546.   
  1547. STOP
  1548.  
  1549. LABEL(error)
  1550.  
  1551.     If the file was not found when the merge tried to nest it,
  1552.  
  1553.     execution moves here.
  1554.  
  1555. PROMPT(File not found. Move INVOICE.FRM to default directory and start merge again.)
  1556.  
  1557.     Send a message to the user.
  1558.  
  1559. WAIT(15)
  1560.  
  1561.     Display the message for 1.5 seconds.
  1562.  
  1563. STOP
  1564.  
  1565.     Terminate execution.
  1566.  
  1567. )
  1568.  
  1569.  
  1570.  
  1571. For another example of ONERROR, see RETURNERROR.
  1572.  
  1573. PAGEOFF
  1574.  
  1575. Use PAGEOFF to eliminate the hard page code [HPg] between copies of the form file in the merged document. Use PAGEON to begin inserting hard page codes again after you have used PAGEOFF.
  1576.  
  1577. PAGEON and PAGEOFF are global to the merge; they may be included in any form or data file and are in effect for all the files in the merge until the opposite command is encountered. PAGEOFF and PAGEON override the option set in the Merge Run dialog box.
  1578.  
  1579. These commands are useful for merging labels or for including multiple records in a document. You can also use PAGEOFF with PRINT to eliminate blank pages between copies of the merged document when merging to the printer.
  1580.  
  1581. For an example of PAGEOFF, see PAGEON.
  1582.  
  1583. PAGEON
  1584.  
  1585. Use PAGEON to reinstate the use of hard page codes between copies of the form file in the merged document. See also PAGEOFF.
  1586.  
  1587. In the example below, the nested form file, list.pf, creates a list of players on a given team. The final result of the merge is a list of the players on each team, one team per page.
  1588.  
  1589.  
  1590.  
  1591. CODES(
  1592.  
  1593. ASSIGN(team;FIELD(team))
  1594.  
  1595.     Assign the current field to a global variable so that the nested
  1596.  
  1597.     form file can use it.
  1598.  
  1599. INSERT(These people are on Team FIELD(team):)
  1600.  
  1601. PAGEOFF
  1602.  
  1603.     This command prevents the insertion of a hard page between
  1604.  
  1605.     iterations of the nested form file.
  1606.  
  1607. NESTFORM(list.frm)
  1608.  
  1609.     This form file produces a list using the Name field of
  1610.  
  1611.     all records whose Team field matches the current Team variable.
  1612.  
  1613. PAGEON
  1614.  
  1615.     This command restores the use of page breaks to allow one team
  1616.  
  1617.     list per page.
  1618.  
  1619. )
  1620.  
  1621. POSTNET(string)
  1622.  
  1623. Use POSTNET to insert a POSTNET bar code into a form file for letters, envelopes, or labels. For the string parameter, you can type the bar code digits or enter a field for the digits.
  1624.  
  1625. The following is a sample form file for an envelope including the return address and a POSTNET bar code:
  1626.  
  1627.  
  1628.  
  1629. JASPER DEAN
  1630.  
  1631. 2745 CHARLES DU DRE PKWY
  1632.  
  1633. MADISON WI 53725-9876
  1634.  
  1635.  
  1636.  
  1637. POSTNET(FIELD(zipcode))
  1638.  
  1639. FIELD(name)
  1640.  
  1641. FIELD(address)
  1642.  
  1643. FIELD(city/state) FIELD(zipcode)
  1644.  
  1645.  
  1646.  
  1647. When this form file is merged, the mailing address will return a different name, address, city/state, and bar code for each record.
  1648.  
  1649. PRINT
  1650.  
  1651. Use PRINT to send the current merged text to the printer. Once the text is sent to the printer, it is no longer in the merged document.
  1652.  
  1653. When you merge to the printer using this command, the usual page break is still inserted between each iteration of the form file. To eliminate the extra page between each copy, insert PAGEOFF before PRINT as shown in the example.
  1654.  
  1655. The data file to be used with the form file in the following example contains 1,000 records. If you were to merge it to the document window, the resulting document would have 1,000 pages. This merge uses PRINT to send each letter to the printer as soon as it is merged.
  1656.  
  1657.  
  1658.  
  1659. ABC COMPANY
  1660.  
  1661. 245 WEST CENTER STREET LONG BEACH CA 90807
  1662.  
  1663.  
  1664.  
  1665. DATE
  1666.  
  1667.  
  1668.  
  1669. FIELD(name)
  1670.  
  1671. FIELD(company)
  1672.  
  1673.  
  1674.  
  1675. Dear FIELD(firstname):
  1676.  
  1677. Thank you for your inquiry regarding our new product.
  1678.  
  1679.   
  1680.   
  1681.   (rest of letter)
  1682.   
  1683.   
  1684.   
  1685. Sincerely,
  1686.  
  1687.  
  1688.  
  1689. Amy Wilcox
  1690.  
  1691. Product Manager
  1692.  
  1693. PAGEOFF PRINT
  1694.  
  1695. PROCESSOFF
  1696.  
  1697. Use PROCESSOFF to end a PROCESSON command.
  1698.  
  1699. For an example of PROCESSON and PROCESSOFF, see CHAINDATA.
  1700.  
  1701. PROCESSON
  1702.  
  1703. Use PROCESSON with PROCESSOFF in a data merge file to ensure that codes are processed even if they are not in the field or record being processed by the form file.
  1704.  
  1705. For an example of PROCESSON and PROCESSOFF, see CHAINDATA.
  1706.  
  1707. PROMPT(message)
  1708.  
  1709. Use PROMPT to display a message that gives instructions to the user.
  1710.  
  1711. For examples of PROMPT, see ONCANCEL and ONERROR.
  1712.  
  1713. QUIT
  1714.  
  1715. Use QUIT to stop the execution of the merge. For example, while a merge is paused at KEYBOARD, you can execute QUIT from the keyboard.
  1716.  
  1717. In a merge, the rest of the form file after QUIT is written out to the resulting merged document before the merge terminates, but any commands after QUIT are not executed. If you don't want the rest of the form file written out, use STOP instead of QUIT.
  1718.  
  1719. If QUIT is used in a data file, the data file is abandoned at that point.
  1720.  
  1721. However, the rest of the form file is written out (but not processed) just as if the command had been encountered in the form file. The merge then terminates.
  1722.  
  1723. The following example is a standard memo sent by a personnel department to all employees before their six-month salary review. The merge ends just after the DATE command, but the rest of the memo is written out to the resulting merged document.
  1724.  
  1725.  
  1726.  
  1727.         MEMO
  1728.  
  1729.  
  1730.  
  1731. To:            KEYBOARD(Enter To information)
  1732.  
  1733. From:        Kim Charleston, Personnel
  1734.  
  1735. Date:        DATE QUIT
  1736.  
  1737. Subject:     Six-month Review Preparation
  1738.  
  1739. ====================================
  1740.  
  1741.   
  1742.   
  1743.   (rest of memo)
  1744.   
  1745.   
  1746.   
  1747. REPEATROW
  1748.  
  1749. Use REPEATROW when merging information into a table from a data file. The REPEATROW command in a row inserts that row for each record in the data file.
  1750.  
  1751. RETURN
  1752.  
  1753. Use RETURN to mark the end of a subroutine and signal the merge to return from a CALL command. RETURN must be paired with CALL, or an error message displays.
  1754.  
  1755. For an example of RETURN, see CALL.
  1756.  
  1757. RETURNCANCEL
  1758.  
  1759. Use RETURNCANCEL to cause execution to leave the current level and return a Cancel to the next higher level. For more information, see Levels.
  1760.  
  1761. In this example, RETURNCANCEL is used to return a cancel from a status checking subroutine.
  1762.  
  1763.  
  1764.  
  1765. CODES(
  1766.  
  1767. ONCANCEL(GO(send message))
  1768.  
  1769.   
  1770.   
  1771.   (During this part of the merge, if the user presses Cancel,
  1772.   
  1773.   execution is transferred to the Send Message label.)
  1774.   
  1775.   
  1776.   
  1777. CALL(check status)
  1778.  
  1779.   
  1780.   
  1781.   (more merge commands)
  1782.   
  1783.   
  1784.   
  1785. STOP
  1786.  
  1787. LABEL(check status)
  1788.  
  1789. IF(VARIABLE(chk)=0)
  1790.  
  1791.     RETURNCANCEL
  1792.  
  1793. ELSE
  1794.  
  1795.     RETURN
  1796.  
  1797. ENDIF
  1798.  
  1799. )
  1800.  
  1801.  
  1802.  
  1803. If the chk variable equals FALSE (0), then the ONCANCEL condition is executed; if it is TRUE, then it returns without executing the ONCANCEL condition.
  1804.  
  1805. RETURNERROR
  1806.  
  1807. Use RETURNERROR to cause execution to leave the current level and return an error to the next higher level. For more information, see Levels.
  1808.  
  1809. In this example, RETURNERROR returns an error from a subroutine that nests a form file.
  1810.  
  1811.  
  1812.  
  1813. CODES(
  1814.  
  1815. ONERROR(GO(error))
  1816.  
  1817.     If an error is generated, execute the Error subroutine.
  1818.  
  1819.   
  1820.   
  1821.   (more merge commands)
  1822.   
  1823.   
  1824.   
  1825. CALL(getfile)
  1826.  
  1827.   
  1828.   
  1829.   (more merge commands)
  1830.   
  1831.   
  1832.   
  1833. STOP
  1834.  
  1835.  
  1836.  
  1837. LABEL(getfile)
  1838.  
  1839.     ONERROR(RETURNERROR)
  1840.  
  1841.     NESTFORM(invoice.frm)
  1842.  
  1843. RETURN
  1844.  
  1845.  
  1846.  
  1847. LABEL(error)
  1848.  
  1849.     If the file was not found when the merge tried to nest it,
  1850.  
  1851.     execution moves here.
  1852.  
  1853. PROMPT(File not found. Move INVOICE.FRM to default directory and start merge again.)
  1854.  
  1855.     Send a message to the user.
  1856.  
  1857. WAIT(15)
  1858.  
  1859.     Display the message for 1.5 seconds.
  1860.  
  1861. STOP
  1862.  
  1863.     Terminate execution
  1864.  
  1865. )
  1866.  
  1867. REWRITE
  1868.  
  1869. Use REWRITE to rewrite the document window. Since none of the merged document is written to the document window during a merge, you may want to use this command to display what has been merged at a certain point.
  1870.  
  1871. In the following example, REWRITE is used to view each letter on the screen as it is merged.
  1872.  
  1873.  
  1874.  
  1875. ABC COMPANY
  1876.  
  1877. 245 WEST CENTER STREET LONG BEACH CA 90807
  1878.  
  1879.  
  1880.  
  1881. DATE
  1882.  
  1883.  
  1884.  
  1885. FIELD(name)
  1886.  
  1887. FIELD(company)
  1888.  
  1889.  
  1890.  
  1891. Dear FIELD(firstname):
  1892.  
  1893. Thank you for your inquiry regarding our new product.
  1894.  
  1895.   
  1896.   
  1897.   (rest of the letter)
  1898.   
  1899.   
  1900.   
  1901. Sincerely,
  1902.  
  1903. Amy Wilcox
  1904.  
  1905. Product Manager
  1906.  
  1907. REWRITE
  1908.  
  1909. STATUSPROMPT(message)
  1910.  
  1911. Use STATUSPROMPT to display a message. The message is displayed during the merge. The message stays in the message window until it is cleared by another command that uses the message window, such as another STATUSPROMPT or a KEYBOARD command.
  1912.  
  1913. For example, if you always run two merges one after the other, you could use STATUSPROMPT to display the prompt "Merge 1 has been completed" at the end of the first merge.
  1914.  
  1915.  
  1916.  
  1917.   
  1918.   
  1919.   (Main body of first form file)
  1920.   
  1921.   
  1922.   
  1923. STATUSPROMPT(Merge 1 has been completed.)
  1924.  
  1925.  
  1926.  
  1927. You could then clear the message window at the end of the second merge by using STATUSPROMPT with no parameters.
  1928.  
  1929.  
  1930.  
  1931.   
  1932.   
  1933.   (Main body of second form file)
  1934.   
  1935.   
  1936.   
  1937. STATUSPROMPT()
  1938.  
  1939. STEPOFF
  1940.  
  1941. Use STEPOFF to turn off a single step execution after it has been turned on. See also STEPON.
  1942.  
  1943. STEPON
  1944.  
  1945. Use STEPON for debugging merges. It causes the merge to execute one step at a time. Between each step, a message indicates what the next command is. The command executes when the user presses any key. Each character is displayed after it is written out to the resulting document.
  1946.  
  1947. You may find it useful to step through merges with Reveal Codes on.
  1948.  
  1949.  
  1950.  
  1951.   
  1952.   
  1953.   (This section will execute normally.)
  1954.   
  1955.   
  1956.   
  1957. STEPON
  1958.  
  1959.   
  1960.   
  1961.   (This section will execute one keystroke at a time.)
  1962.   
  1963.   
  1964.   
  1965. STEPOFF
  1966.  
  1967.   
  1968.   
  1969.   (This section will execute normally.)
  1970.   
  1971.   
  1972.   
  1973. STOP
  1974.  
  1975. Use STOP to stop all execution. It is similar to QUIT, except that the rest of the form file is not read in. If this command is found in a nested file, execution is not returned to the parent file. Chained files are also not executed.
  1976.  
  1977. While an executing merge is paused at KEYBOARD, you can execute STOP from the keyboard.
  1978.  
  1979. For an example of STOP, see IFEXISTS.
  1980.  
  1981. STRLEN(expr)
  1982.  
  1983. Use STRLEN to determine the length of a variable or of the value returned by an expression. This command is useful for validating or restricting the length of user input.
  1984.  
  1985. You can use FIELD, VARIABLE, text, or complex expressions in the argument expr.
  1986.  
  1987. For an example of STRLEN, see SUBSTR.
  1988.  
  1989. STRPOS(expr;subexpr)
  1990.  
  1991. Use STRPOS to determine the position of a subexpr within an expr.
  1992.  
  1993. For an example of STRPOS, see SUBSTR.
  1994.  
  1995. SUBSTDATA(filename)
  1996.  
  1997. Use SUBSTDATA to change to the named data file and start with the first record in that file. The merge does not return to the original data file. If you substitute a file that is not found, or no file, an error is returned. You can use ONERROR to determine what should happen if this error occurs.
  1998.  
  1999. In the following example, two data files are used, each sorted by ZIP Code in descending order, so that any records where the ZIP field is blank will be at the end of the file. SUBSTDATA causes the records with no ZIP Code to be skipped, and the next data file to be used.
  2000.  
  2001.  
  2002.  
  2003. CODES(
  2004.  
  2005. IFBLANK(ZIP)
  2006.  
  2007.     SUBSTDATA(file2.dat)
  2008.  
  2009. ENDIF
  2010.  
  2011. )
  2012.  
  2013. SUBSTFORM(filename)
  2014.  
  2015. Use SUBSTFORM to change to the named form file. SUBSTFORM is similar to NESTFORM and CHAINFORM. The difference is that the named form file is used instead of the current form file from the point of this command on. The merge does not return to the original form file; no commands following this one in the original form file are executed. Local variables in a previous form file are erased.
  2016.  
  2017. If you substitute either a file that is not found or no file, an error is returned. You can use ONERROR to determine what should happen if this error occurs.
  2018.  
  2019. In the following example, the data file has a Days Overdue field. The merge begins using the form file invoice.frm, which substitutes a different form file depending on the number in the Days Overdue field.
  2020.  
  2021. At the end of each substituted file, the record pointer is moved to the next record, and invoice.frm is substituted, so that it will execute again.
  2022.  
  2023.  
  2024.  
  2025. CODES(
  2026.  
  2027. ASSIGN(days;FIELD(Days Overdue) DIV 30)
  2028.  
  2029. SWITCH(VARIABLE(days))
  2030.  
  2031.     CASEOF(0)
  2032.  
  2033.         SUBSTFORM(under30.frm)
  2034.  
  2035.     CASEOF(1)
  2036.  
  2037.         SUBSTFORM(under60.frm)
  2038.  
  2039.     CASEOF(2)
  2040.  
  2041.         SUBSTFORM(under90.frm)
  2042.  
  2043.     DEFAULT
  2044.  
  2045.         SUBSTFORM(90&over.frm)
  2046.  
  2047. ENDSWITCH
  2048.  
  2049. )
  2050.  
  2051.  
  2052.  
  2053. In this example, the following code would be placed at the end of each substituted form file.
  2054.  
  2055.  
  2056.  
  2057.   
  2058.   
  2059.   (body of file)
  2060.   
  2061.   
  2062.   
  2063. NEXTRECORD
  2064.  
  2065. SUBSTFORM(invoice.frm)
  2066.  
  2067. SUBSTR(expr;start;length)
  2068.  
  2069. Use SUBSTR to extract a portion (substring) of the expression specified in the expr parameter. You can specify which part of the expression to use with the start and length parameters. The start parameter counts from the left side of the expr. The length parameter specifies how many characters are included in the substring.
  2070.  
  2071. For example, if a form file contains the statement SUBSTR(think;2;2), the substring "hi" is inserted into the merged document. The start parameter has the value 2, so the substring begins with the second character in the expr parameter ("h."). The count parameter has the value 2, so the substring contains two characters ("h" and "i").
  2072.  
  2073. You can use FIELD, VARIABLE, text, or complex expressions in the argument expr.
  2074.  
  2075. In this example, the data file has a name field where the names are stored in the format "Last, First." SUBSTR extracts the first name from the name field. STRPOS is used to find the beginning of the first name (2 characters after the start of the comma and space). STRLEN is used to find the length of the first name (by subtracting the starting position of the first name from the length of the full name).
  2076.  
  2077.  
  2078.  
  2079. CODES(
  2080.  
  2081. ASSIGN(start;STRPOS(FIELD(name);, )+2)
  2082.  
  2083. ASSIGN(length;STRLEN(FIELD(name)-VARIABLE(start)))
  2084.  
  2085. ASSIGN(firstname;SUBSTR(FIELD(name);VARIABLE(start);VARIABLE(length)))
  2086.  
  2087. VARIABLE(firstname)
  2088.  
  2089. )
  2090.  
  2091. SWITCH(expr)
  2092.  
  2093. Use SWITCH with CASEOF, CONTINUE, DEFAULT, and ENDSWITCH to evaluate input and execute different functions depending on the input.
  2094.  
  2095. The expression in SWITCH must match the expression in CASEOF exactly. For example, "y" does not match "Y." If no match is found in the SWITCH statement, execution continues after the SWITCH statement. You can use DEFAULT as the last case in the command to handle all cases that do not match. You can use CONTINUE to perform the commands for more than one case.
  2096.  
  2097. In the following example, SWITCH is used to include certain documents in the merge file based on the value of the class field in a data file. If the class field does not match any of the first three cases, DEFAULT is executed, and the file general.fil is included in the merged document.
  2098.  
  2099. Because each of the other cases ends with CONTINUE, the DEFAULT case and any cases following the one selected are executed along with the case selected. For example, if the class field contains 2nd, then the files 2ndclass.fil, 3rdclass.fil, and general.fil would all be included in the merged document for that record.
  2100.  
  2101.  
  2102.  
  2103. Dear FIELD(name):
  2104.  
  2105. You have chosen to travel FIELD(class) class. This allows you to enjoy the following benefits during your trip:
  2106.  
  2107. CODES(
  2108.  
  2109. SWITCH(FIELD(class))
  2110.  
  2111.     CASEOF(1st)
  2112.  
  2113.         DOCUMENT(1stclass.fil)
  2114.  
  2115.         CONTINUE
  2116.  
  2117.     CASEOF(2nd)
  2118.  
  2119.         DOCUMENT(2ndclass.fil)
  2120.  
  2121.         CONTINUE
  2122.  
  2123.     CASEOF(3rd)
  2124.  
  2125.         DOCUMENT(3rdclass.fil)
  2126.  
  2127.         CONTINUE
  2128.  
  2129.     DEFAULT
  2130.  
  2131.         DOCUMENT(general.fil)
  2132.  
  2133.     ENDSWITCH
  2134.  
  2135. )
  2136.  
  2137.  
  2138.  
  2139. For another example of SWITCH, see FORNEXT.
  2140.  
  2141. SYSTEM(sysvar)
  2142.  
  2143. Use SYSTEM to return the value of the given system variable. System variables allow the merge to be aware of the current state of WordPerfect.
  2144.  
  2145. In the following example, the merge includes only the first three records of the form file. When the merge reaches the fourth page of the resulting merge document, it stops.
  2146.  
  2147.  
  2148.  
  2149. CODES(
  2150.  
  2151. IF(SYSTEM(Page)=4)
  2152.  
  2153.     STOP
  2154.  
  2155. ENDIF
  2156.  
  2157. )
  2158.  
  2159.   
  2160.   
  2161.   (Body of the form file)
  2162.   
  2163.   
  2164.   
  2165.  
  2166.  
  2167. System variables are listed on the Parameter Entry dialog box when you choose the SYSTEM command.
  2168.  
  2169. TOLOWER(expr)
  2170.  
  2171. Use TOLOWER to lowercase each character in the returned expression expr.
  2172.  
  2173. For an example of TOLOWER, see CAPS.
  2174.  
  2175. TOUPPER(expr)
  2176.  
  2177. Use TOUPPER to uppercase each character in the returned expression expr.
  2178.  
  2179. For an example of TOUPPER, see CAPS.
  2180.  
  2181. VARIABLE(var)
  2182.  
  2183. Use VARIABLE to access the contents of global and local variables. If you have both a global and a local variable with the same name, this command accesses the local variable. There is no way to access global variables while local variables of the same name exist. For an explanation of global and local variables, see Merge variables.
  2184.  
  2185. After you assign a value to a variable (using ASSIGN(var;expr) or ASSIGNLOCAL(var;expr)), you can place the VARIABLE command anywhere you would normally place the variable contents. You can place it as an argument for another command, as part of an argument for another command, or by itself.
  2186.  
  2187. For an example of VARIABLE, see SUBSTR.
  2188.  
  2189. WAIT(10ths second)
  2190.  
  2191. Use WAIT to delay further execution of the merge for the indicated time. This command is useful when you want a message to be displayed for a certain amount of time. The wait time is specified in tenths of a second (20 = 2 seconds).
  2192.  
  2193. For an example of WAIT, see ONCANCEL.
  2194.  
  2195. WHILE(expr)
  2196.  
  2197. Use WHILE to execute commands repeatedly. While the expression expr is true, the commands between WHILE and ENDWHILE are repeatedly executed. This command is like FORNEXT, except that it does not increment a value each time through the loop. In order to end the loop, you must use BREAK or another command that will force the expression to be evaluated as false. For more information, see Loops.
  2198.  
  2199. Remember that if you use a variable in expr, the variable must already exist before the WHILE command is executed.
  2200.  
  2201. For an example of WHILE, see NEXTRECORD.
  2202.  
  2203. ASSIGNLOCAL(var;expr)
  2204.  
  2205. Use ASSIGNLOCAL to assign the value returned by expr to the local variable var. Local variables are accessible only to the current file; they are deleted when the merge is finished or the file is exited. See also ASSIGN(var;expr)
  2206.  
  2207. For an example of ASSIGNLOCAL, see CTON.
  2208.  
  2209. Working with levels, loops, and merge variables
  2210.  
  2211. The following topics provide information about using levels, loops, and merge variables when you program a merge.
  2212.  
  2213. Levels
  2214.  
  2215. Loops
  2216.  
  2217. Merge variables
  2218.  
  2219. System variables compared to user defined variables
  2220.  
  2221. Global variables compared to local variables
  2222.  
  2223. Naming variables
  2224.  
  2225. Variable contents
  2226.  
  2227. Assigning variables
  2228.  
  2229. Executing variables
  2230.  
  2231. Variable duration
  2232.  
  2233. Operations on variables
  2234.  
  2235. Levels
  2236.  
  2237. In a merge document you can have as many as 40 levels of execution per file. IF commands do not require a level; they can be nested indefinitely. Each SWITCH, FORNEXT, or WHILE uses one level.
  2238.  
  2239. NESTMACRO, NESTFORM, and NESTDATA do not require an execution level, because each nested file has 40 new execution levels.
  2240.  
  2241. However, they do require a nesting level. You can nest files 10 deep.
  2242.  
  2243. Merge uses separate stacks to maintain execution levels and nesting levels.
  2244.  
  2245.      Merge variables
  2246.  
  2247. A variable represents a place in memory where data is stored. As its name indicates, the data in a variable is changeable. You can use variables to calculate and keep track of text and numeric values that change during a merge.
  2248.  
  2249. System variables compared to user defined variables
  2250.  
  2251. There are two major types of variables in WordPerfect: system variables and user-defined variables. System variables are variables that WordPerfect creates and maintains; they contain information about the current state of the application. You cannot change the names or contents of these variables, but you can use their contents at any given time. System variables are listed on the Parameter Entry dialog box when you choose the System command.
  2252.  
  2253. User-defined variables are variables that you create. You determine the name and contents of these variables when you assign them. You can also perform operations on them to change their contents. There are two subcategories of user-defined variables: global and local.
  2254.  
  2255. Global variables compared to local variables
  2256.  
  2257. Global variables are accessible from anywhere inside a merge or a macro. All global merge variables can be read by macros; macro variables can be read by merge commands if the PERSIST command is used in the macro.
  2258.  
  2259. Local variables are available only in Merge and are stored in a place in memory separate from global variables. They are accessible only from the file in which they are defined. For example, if you create a local variable named Number in a form file, the data file or other form files cannot access the information stored in it. When you nest merge files, the local variables in the parent file cannot be used in the nested file.
  2260.  
  2261. When you return to the parent file, the local variables in the nested file no longer exist, but the local variables in the parent file are once again accessible.
  2262.  
  2263. Local variables take precedence over global variables. For example, suppose you have both a global and a local variable named Number. If you try to access the global variable Number from inside a file where the local variable Number is accessible, you will get the contents of the local variable. The global variable Number still exists, but is inaccessible until you are no longer accessing the current merge file.
  2264.  
  2265. Naming variables
  2266.  
  2267. Variable names can be as many as 30 characters long for both global and local variables. Although you can use the same name for a local and a global variable, you cannot use the same name for any two local variables or any two global variables. You should not use the same name for a local variable and a label.
  2268.  
  2269. Variable names are not case sensitive. Abc, AbC, ABC, and abc are read as the same variable.
  2270.  
  2271. Variables receive their names when they are assigned. For more information, see Assigning variables.
  2272.  
  2273. Variable contents
  2274.  
  2275. All user-defined variables can contain text or numbers. A user-defined variable can hold 127 characters.
  2276.  
  2277. Assigning variables
  2278.  
  2279. You assign a global variable with ASSIGN and a local variable with ASSIGNLOCAL. For example, the following two statements assign two different variables, one global and one local:
  2280.  
  2281.   ASSIGN(Number;45)
  2282.   
  2283.   ASSIGNLOCAL(Number;36)
  2284.   
  2285. ASSIGN creates a global variable named Number with "45" as its contents. ASSIGNLOCAL creates a separate, local variable named Number with "36" as its contents. For more information, see ASSIGN(var;expr) and ASSIGNLOCAL(var;expr).
  2286.  
  2287. In addition to using ASSIGN and ASSIGNLOCAL, the following commands also assign variables:
  2288.  
  2289.   CHAR
  2290.   
  2291.   FOREACH
  2292.   
  2293.   GETSTRING
  2294.   
  2295.   LOOK
  2296.   
  2297. The following rules determine whether the variable assigned by CHAR, GETSTRING, and LOOK are local or global in a merge:
  2298.  
  2299.   If a local variable with the name used in the command exists, the command assigns the value to the local variable.
  2300.   
  2301.   If no local variable with the name used in the command exists, but a global variable by that name does exist, the command assigns the value to the global variable.
  2302.   
  2303.   If no variable with the name used in the command exists, a global variable of that name is created and assigned by the command.
  2304.   
  2305. FOR and FOREACH in Merge assign variables by the same rules as above, except that if no variable with the name used in the command exists (the third rule), a local variable is created and assigned by the command. This feature allows recursion using FOR and FOREACH in Merge.
  2306.  
  2307. If a variable already exists and you assign new contents to it, the previous contents will be replaced without warning.
  2308.  
  2309. Executing variables
  2310.  
  2311. You can execute (write out) a variable anywhere you want its contents to appear. For example, by executing a variable you can do the following:
  2312.  
  2313.   Use the contents of the variable as a subroutine
  2314.   
  2315.   Insert the contents as text in a document or in the message strings of programming commands
  2316.   
  2317.   Provide variable arguments in other programming commands
  2318.   
  2319. To execute a variable, use VARIABLE. For example, the statement VARIABLE(Number) would execute the variable named Number.
  2320.  
  2321. Variable duration
  2322.  
  2323. Local variables exist only in the file in which they are defined. Once you quit the file that defined the variables or once the merge ends, the local variables are erased (and the memory assigned to them is released). However, the contents of global variables remain in memory until you exit WordPerfect. To conserve memory, you should use local variables instead of global variables whenever possible.
  2324.  
  2325. If you want to erase a variable without exiting a file or exiting WordPerfect, assign nothing to the variable by using the following commands: ASSIGN(var;) or ASSIGNLOCAL(var;). These commands empty the variable of its contents and release the memory used by the variable. After you use this command, the variable no longer exists. It is a good idea to empty variables at the beginning of the merge in which they are used (unless the merge assigns new contents to them).
  2326.  
  2327. Operations on variables
  2328.  
  2329. All variables can be compared to each other, and user-defined variables can have other operations performed on them. Operations are performed using various programming commands. See "Working with merge expressions" and "Merge Programming Commands."
  2330.  
  2331. Loops
  2332.  
  2333. Whenever the same commands repeat several times, that section of the merge is called a loop. When you create a loop, it is very important to have a way for the loop to end. If the loop does not have an end, there is no way to stop execution without pressing ESC or CTRL + ENTER.
  2334.  
  2335. There are many types of loops you can create with merge programming commands.
  2336.  
  2337. You can use an IF structure or you can use FORNEXT or WHILE. You can also create loops by going to or calling subroutines (with GO or CALL). The structure you should use for any given loop depends on the task you are trying to accomplish.
  2338.  
  2339. Working with merge expressions
  2340.  
  2341. Merge expressions are used to determine values in the ASSIGN, ASSIGNLOCAL, CAPS, CASEOF, CTON, FIRSTCAP, FOREACH, FORNEXT, IF, NTOC, STRLEN, STRPOS, SUBSTR, SWITCH, TOLOWER, TOUPPER, and WHILE commands. Expressions can perform operations on either numbers or strings.
  2342.  
  2343. The following topics explain how to use expressions when you program a merge in WordPerfect:
  2344.  
  2345. Numeric expressions
  2346.  
  2347. String expressions
  2348.  
  2349. Expression evaluation
  2350.  
  2351. Operator precedence
  2352.  
  2353. String delimiters
  2354.  
  2355. Other merge delimiters
  2356.  
  2357. Numeric expressions
  2358.  
  2359. Numeric expression values must contain only integers (or variables that contain integers).
  2360.  
  2361. You can use signed numbers in expressions. The highest positive number you can use is 2,147,483,647. Numbers higher than that are considered negative in WordPerfect. For information, see Negative numbers. The lowest negative number you can use is --2,147,483,648.
  2362.  
  2363. If you try to use an invalid numeric expression, the expression is treated as a text string. Examples of invalid numeric expressions are characters other than numbers and valid operators or expressions that evaluate to numbers outside the numeric limits.
  2364.  
  2365. The following is a list of numeric expressions. In this list, the terms n1 and n2 represent number 1 and number 2. Although only a single operator is illustrated in each example below, you can use several operators as well as parentheses in expressions. For definitions of the operations used in the following table, see "Expression terms."
  2366.  
  2367. Expression    Operation
  2368.  
  2369. NOT n1    Returns the logical (0 or -1) NOT of n1.
  2370. Examples: NOT 0 is -1. NOT 2 is 0.
  2371.  
  2372. !n1    Returns the arithmetic (bitwise) NOT of n1.
  2373. Examples: !0 is -1. !2 is -3.
  2374.  
  2375. -n1    Returns the negative of n1.
  2376. Example: If variable Num holds 5, -VARIABLE(Num) is -5.
  2377.  
  2378. n1+n2    Returns the sum of n1 and n2.
  2379. Example: 5+4 is 9.
  2380.  
  2381. n1-n2    Returns the difference of n1 and n2.
  2382. Example: 10-1 is 9.
  2383.  
  2384. n1*n2    Returns the product of n1 and n2.
  2385. Example: 6*5 is 30.
  2386.  
  2387. n1/n2 or n1 DIV n2    Returns the integer quotient of n1 and n2.
  2388. Examples: 20/5 is 4. 5 DIV 2 is 2.
  2389.  
  2390. n1%n2 or n1 MOD n2    Returns the remainder of the quotient of n1 and n2.
  2391. Examples: 20%5 is 0. 5 MOD 2 is 1.
  2392.  
  2393. n1 AND n2    Returns the logical (0 or -1) AND of n1 and n2.
  2394. Examples: 0 AND -1 is 0. 3 AND 4 is -1.
  2395.  
  2396. n1 & n2    Returns the arithmetic (bitwise) AND of n1 and n2.
  2397. Examples: 7&4 is 4. 3&4 is 0.
  2398.  
  2399. n1 OR n2    Returns the logical (0 or -1) OR of n1 and n2.
  2400. Examples: 0 OR -1 is -1. 3 OR 4 is -1.
  2401.  
  2402. n1|n2    Returns the arithmetic (bitwise) OR of n1 and n2.
  2403. Examples: 7|4 is 7. 3|4 is 7.
  2404.  
  2405. n1 XOR n2    Returns the logical (0 or -1) XOR (exclusive OR) of n1 and n2.
  2406. Examples: 0 XOR -1 is -1. 3 XOR 4 is 0.
  2407.  
  2408. n1=n2    Returns a true value (-1) if n1 and n2 are equal; otherwise, returns a false value (0).
  2409. Examples: If variable 1 holds 5, then VARIABLE(1)=5 is true, and VARIABLE(1)=3 is false.
  2410.  
  2411. n1!=n2 or n1<>n2    Returns a true value (-1) if n1 and n2 are not equal; otherwise, returns a false value (0).
  2412. Examples: If variable 1 holds 5, then VARIABLE(1)!=3 is true, and VARIABLE(1)<>5 is false.
  2413.  
  2414. n1>n2    Returns a true value (-1) if n1 is greater than n2; otherwise, returns a false value (0).
  2415. Examples: 6>4 is true. 4>6 is false.
  2416.  
  2417. n1<n2    Returns a true value (-1) if n1 is less than n2; otherwise, returns a false value (0).
  2418. Examples:2<10 is true. 10<2 is false.
  2419.  
  2420. n1>=n2    Returns a true value (-1) if n1 is greater than or equal to n2; otherwise, returns a false value (0).
  2421. Examples: 6>=6 is true. 4>=6 is false.
  2422.  
  2423. n1<=n2    Returns a true value (-1) if n1 is less than or equal to n2; otherwise, returns a false value (0).
  2424. Examples: 2<=2 is true. 10<=2 is false.
  2425.  
  2426. Expression evaluation
  2427.  
  2428. An expression must be written according to the rules and syntax in this appendix for WordPerfect to evaluate it correctly. The following information will help you create and use expressions.
  2429.  
  2430. When an expression is encountered in a command, the expression is evaluated first, and the result of the expression is used to complete the command. For example, in the statement ASSIGN(1;VARIABLE(1)+1), the expression is VARIABLE(1)+1.
  2431.  
  2432. When the expression is evaluated, the contents of variable 1 are incremented by one. The assignment is then performed, replacing the old contents of variable 1 with the result of the expression.
  2433.  
  2434. In several of the expressions, the result of the operation is either true or false. WordPerfect assigns a numeric value to true (-1) and false (0). These values were chosen because they are opposites (numeric complements) of each other. For information, see Bitwise NOT in "Expression Terms." WordPerfect interprets any non-zero numeric value as true, but when it assigns a value for true, it assigns -1.
  2435.  
  2436. In the following example, the first assignment statement assigns false (0) to variable 1, the second assignment statement assigns true (-1), the logical opposite of false, to variable 1, and the third assignment statement assigns true (-1) to variable 1.
  2437.  
  2438.  
  2439.  
  2440. ASSIGN(1;5=4)
  2441.  
  2442. ASSIGN(1;NOT VARIABLE(1))
  2443.  
  2444. ASSIGN(1;5!=4)
  2445.  
  2446.  
  2447.  
  2448. The order in which the various operators are applied in an expression is not simply the order in which they occur. WordPerfect uses an order of precedence that determines which operators are used first, second, and so forth. For example, in the expression 4+7*8, there is a different result depending on whether the addition is performed before or after the multiplication. For more information about the order of evaluation, see Operator Precedence.
  2449.  
  2450. Operator precedence
  2451.  
  2452. WordPerfect supports expressions with several operators. Therefore, an order of evaluation must be followed. The operator precedence is similar to the precedence for mathematical operators. The following table shows the order in which operators are applied:
  2453.  
  2454. 1. - (unary minus), + (unary plus), ! (bitwise NOT), NOT (logical NOT)
  2455.  
  2456. 2. * (multiply), / (divide), DIV (divide), % (mod), MOD (mod)
  2457.  
  2458. 3. - (subtract), + (add)
  2459.  
  2460. 4. < (less than), > (greater than), = (equal to), != (not equal to), <= (less than or equal to), >= (greater than or equal to) Relational operators also work on strings.
  2461.  
  2462. 5. & (bitwise AND), AND (logical AND), | (bitwise OR), OR (logical OR), XOR (exclusive OR)
  2463.  
  2464. You can override the operator precedence by placing parentheses around the elements you want evaluated first. Elements inside of parentheses are always evaluated before the elements outside. If parentheses are nested, the innermost parentheses are evaluated first.
  2465.  
  2466. In the expression 4+7*8, the multiplication (7*8) is performed first, followed by the addition, because multiplication has a higher precedence than addition. The result is 60. To perform the addition first, type (4+7)*8. In this case, the result is 88.
  2467.  
  2468. String delimiters
  2469.  
  2470. A string delimiter is a character that marks the beginning or end of a string. In string operations, quotation marks (") serve as string delimiters. In most cases, string delimiters are not needed. Any expression that cannot be evaluated as a valid numeric expression is considered a string.
  2471.  
  2472. However, if you want an expression to remain a string even though it could be evaluated as a numeric expression, surround the expression with quotation marks. For example, if you assign a phone number to a variable, but do not surround the number in quotes, the phone number is evaluated as a numeric expression. For example, the command ASSIGN(1;555-1555) assigns the result of subtracting 1555 from 555 (-1000) to variable 1. The command ASSIGN(1;"555-1555") assigns the string 555-1555 to variable 1.
  2473.  
  2474. Other merge delimiters
  2475.  
  2476. A merge delimiter is a word or character that marks the beginning or end of a parameter or argument. Word delimiters can include such reserved words as AND, OR, NOT.
  2477.  
  2478. Semi-colons (;) serve as merge delimiters in merge commands with multiple parameters (SUBSTR(expr;start;length). When a semi-colon is encountered during the merge, it is treated as ending the parameter unless the parameter is within quotation marks.
  2479.  
  2480. String expressions
  2481.  
  2482. A string is any sequence of one or more characters, including spaces. For example, 245, Strawberry, QB12, Z, and Personal Computer are strings. Quotation marks are not necessary to define strings.
  2483.  
  2484. The expressions outlined in the following table are used to compare strings. The terms s1 and s2 represent string 1 and string 2.
  2485.  
  2486. Expression    Operation
  2487.  
  2488. s1=s2    Returns a true value (-1) if string 1 is identical (including case) to string 2; otherwise, returns a false value (0).
  2489. Examples: blue=blue is true. blue=BLUE is false.
  2490.  
  2491. s1!=s2 or s1<>s2    Returns a true value (-1) if string 1 is not identical (including case) to string 2; otherwise, returns a false value (0).
  2492. Examples: If variable 1 holds the string "thread," then VARIABLE(1)!=rope is true, and VARIABLE(1)<>thread is false.
  2493.  
  2494. s1>s2    Returns a true value (-1) if string 1 is greater than* string 2; otherwise, returns a false value (0).
  2495. Examples: abcd>aabcd is true. a>A is true.
  2496.  
  2497. s1<s2    Returns a true value (-1) if string 1 is less than* string 2; otherwise, returns a false value (0).
  2498. Examples: aabcd<abcd is true. A<a is true.
  2499.  
  2500. s1>=s2    Returns a true value (-1) if string 1 is greater than* or equal to string 2; otherwise, returns a false value (0).
  2501. Examples: abcd>=abcd is true. a>=A is true.
  2502.  
  2503. s1<=s2    Returns a true value (-1) if string 1 is less than* or equal to string 2; otherwise, returns a false value (0).
  2504. Examples: abcd<=abcd is true. A<=a is true.
  2505.  
  2506. * In a string comparison, the WordPerfect character set values are compared. For information, see WordPerfect character set values.
  2507.  
  2508. Expression terms
  2509.  
  2510. The following are technical terms used in the discussion of expressions. Understanding these terms is not essential to performing merges. These definitions are provided for those who are familiar with basic programming concepts.
  2511.  
  2512. Bitwise Operation
  2513.  
  2514. Bitwise AND (&)
  2515.  
  2516. Bitwise NOT (!)
  2517.  
  2518. Bitwise OR (|)
  2519.  
  2520. Evaluate the Expression
  2521.  
  2522. Exclusive OR (XOR)
  2523.  
  2524. Logical AND (AND)
  2525.  
  2526. Logical NOT (NOT)
  2527.  
  2528. Logical OR (OR)
  2529.  
  2530. Negative Numbers
  2531.  
  2532. WordPerfect character set values
  2533.  
  2534. Bitwise operation
  2535.  
  2536. In computer language, numbers are represented as a series of 16 bits. A bit can only have a value of 1 or 0. Each 16-bit series (or column) represents a numeric value (such as 1, 2, 4, 8 and so on). The following table outlines some values and their corresponding bits.
  2537.  
  2538. Value    Bits
  2539.  
  2540. 0    0000000000000000
  2541.  
  2542. -1    1111111111111111
  2543.  
  2544. -3    1111111111111101
  2545.  
  2546. -21    1111111111101011
  2547.  
  2548. 3    0000000000000011
  2549.  
  2550. 4    0000000000000100
  2551.  
  2552. 7    0000000000000111
  2553.  
  2554. 21    0000000000010101
  2555.  
  2556. 47    0000000000101111
  2557.  
  2558. A bitwise operation works on one column at a time (starting with the right column) using a single bit from each number. The operation is done 16 times so each bit of each number is operated on.
  2559.  
  2560. Bitwise AND (&)
  2561.  
  2562. A bitwise AND operation compares the bits of two numbers. When both numbers have a 1 bit in the same position (for example, there is a 1 bit in column 1 [the right column] of the first number and the second number), a 1 is placed in that position in the result. The following table demonstrates the way the expression 21&47 is evaluated.
  2563.  
  2564. Value    Bits
  2565.  
  2566. 21    0000000000010101
  2567.  
  2568. 47    0000000000101111
  2569.  
  2570. 21&47    0000000000000101
  2571.  
  2572. The resulting bits represent the number 5, so 21&47=5.
  2573.  
  2574. Bitwise NOT (!)
  2575.  
  2576. A bitwise NOT operation takes the bits of the number and complements them. For example, if the expression is !0 (0 is 0000000000000000), the resulting value is -1 (-1 is 1111111111111111).
  2577.  
  2578. Bitwise OR (|)
  2579.  
  2580. A bitwise OR operation compares the bits of both numbers. When either number has a 1 bit in the same position (for example, there is a 1 bit in column 1 [the right column] of the first number or the second number), a 1 is placed in that position in the result. For example, the expression 21|47 is evaluated as shown in the following table:
  2581.  
  2582. Value    Bits
  2583.  
  2584. 21    0000000000010101
  2585.  
  2586. 47    0000000000101111
  2587.  
  2588. 21|47    0000000000111111
  2589.  
  2590. The resulting bits represent the number 63, so 21|47=63.
  2591.  
  2592. Evaluate the expression
  2593.  
  2594. Perform the operation(s) on the expression.
  2595.  
  2596. Exclusive OR (XOR)
  2597.  
  2598. A logical XOR operation evaluates two expressions and returns a true (-1) if one, but not both, of the expressions is true. If both expressions are false or both are true, XOR returns a false (0). For example, 1=1 XOR 2=3 is true (-1), because only one of the expressions being evaluated is true. 6>3 XOR 3>1 is false (0), because both expressions are true.
  2599.  
  2600. Logical AND (AND)
  2601.  
  2602. A logical AND operation evaluates two expressions and returns a true (-1) if both expressions are true. In all other cases, it returns a false (0). For example, 1=1 AND 2=3 is false (0), because one of the expressions being evaluated is false. 6>3 AND 3>1 is true (-1), because both expressions are true.
  2603.  
  2604. Logical NOT (NOT)
  2605.  
  2606. A logical NOT operation returns the logical opposite (0 or --1) of the expression. WordPerfect interprets any nonzero numeric value as true, but when it assigns a value for true, it assigns -1. For example, NOT 2 is false (0), because 2 is evaluated as true. NOT 0 is true (-1).
  2607.  
  2608. Logical OR (OR)
  2609.  
  2610. A logical OR operation evaluates two expressions and returns a true (-1) if either or both expressions are true. If both expressions are false, it returns a false (0). For example, 1=1 OR 2=3 is true (-1), because one of the expressions being evaluated is true.
  2611.  
  2612. 6<3 OR 3<1 is false (0), because both expressions are false.
  2613.  
  2614. Negative numbers
  2615.  
  2616. In WordPerfect, negative numbers are represented as large positive numbers, from 2,147,483,648 to 4,294,967,295. The number
  2617.  
  2618. 4,294,967,295 is -1, 4,294,967,294 is -2, and so on. To determine the number WordPerfect uses to represent any given negative number from -1 to -2,147,483,648, use the following formula:
  2619.  
  2620. 4,294,967,296 - |x|
  2621.  
  2622. where x is the negative number whose equivalent you are trying to find. For example, to find the equivalent of -3,
  2623.  
  2624. 4,294,967,296 - 3 = 4,294,967,293
  2625.  
  2626. To find the negative number (n) represented by a given equivalent, use this formula:
  2627.  
  2628. x - 4,294,967,296=n
  2629.  
  2630. where x is the equivalent. For example, to find the negative number represented by 4,294,967,293,
  2631.  
  2632. 4,294,967,293 - 4,294,967,296 = -3
  2633.  
  2634. You can assign variables to be negative numbers by using the minus (-) operator or by using the WordPerfect equivalent. Do not use commas or other punctuation in the equivalent. For example,
  2635.  
  2636. ASSIGN(number;-1)
  2637.  
  2638. is the same as
  2639.  
  2640. ASSIGN(number;4294967295)
  2641.  
  2642. For more information about creating numeric expressions, see Numeric Expressions.
  2643.  
  2644. WordPerfect character set values
  2645.  
  2646. WordPerfect assigns a unique value to each character in each WordPerfect character set. For more information, see the descriptions for the CTON and NTOC commands under "Merge Programming Commands." This is called the WordPerfect character set value. In a string comparison, the character set values are compared.
  2647.  
  2648. For characters in the same character set, one character is considered "less than" another character if the first character comes before the second character. For example, in character set 0, "3" is less than "4" and "A" is less than "a." For characters in different character sets, the character from the character set with the lower numerical value is considered "less than" the character from the higher numerical character set. For example, any character from character set 2 is less than any character from character set 3.
  2649.  
  2650.  
  2651.  
  2652.  
  2653. 129
  2654.  
  2655.  
  2656.  
  2657.