Top Navigational Bar

Merge - Explanation Of {IF}, {IF NOT BLANK} A
DocumentID: 652153
Revision Date: 29-Feb-96 8:29:14 PM

The information in this document applies to:
WordPerfect® 5.1 for DOS

Problem

Solutions: This memo explains the purpose of the {IF}, {IF NOT BLANK} and the {IF BLANK} merge statements. WordPerfect 5.1's merge language makes it possible to make many more selections when merging. The commands have also been adapted to work with Tables. To access these commands, press Shift-F9, 6 for more.

{IF}
The {IF} statement is very popular. Customers may use the {IF} statement when wanting to merge certain records only if one or two conditions exist. When using the {IF} statement, it should always be paired with an {END IF} command. The {END IF} statement functions somewhat like a period in a regular sentence. It must be included for the merge to work properly.

Users may also use the {ELSE} statement with {IF}. The {ELSE} statement functions like the word or in a conditional sentence. For example, {IF} it rains today we will go to the mall {ELSE} we will go to the park for a picnic {END IF}.

Another example of using the {IF} statement would be when wanting a merge to create a list of all of the females included on a file. The syntax for such a procedure, if a gender field is present, would be:
            {IF}{FIELD}gender~=Female~
                  {FIELD}name~, {FIELD}address~
            {END IF}

This is very close to the final form needed for the merge. There is, however, one problem. Computers work only with numbers and because of this, WordPerfect has no idea what female is. Because of this, the word female must be enclosed in quotation marks. The quotation marks tell WordPerfect to compare what is in the quotation marks instead of trying to equate the information in number form. Because female will be in quotes, the command {FIELD}gender~ should also be enclosed in quotation marks. Without the quotation marks, the computer will try to compare the word female with a number since it thinks the field is a number unless told otherwise. The final form would look like the following:
            {IF}"{FIELD}gender~"="Female"~
                  {FIELD}name~, {FIELD}address~
            {END IF}
The tilde after the word female works like a comma; it ends the first part of the condition. The tilde could be treated like the word then. ({IF} field gender equals female {THEN} print the name and address.)

In this example it is possible for the word company to appear in the gender field. If so, and the user would like a list of all males and females but not companies the expression would something like the following:
            {IF}"{FIELD}gender~"="Female"|
                  "{FIELD}gender~"="Male"~
                        {FIELD}name~, {FIELD}address~
            {END IF}
(The two vertical bars or pipes represent the or command.) When using the vertical bars, the syntax tells the program to print the name an address if the gender field is equal to female or male. Since the company name would not meet this criteria, WP will skip the company names and only print the male and female information.

The {IF} command can be used to pull certain records from a file containing a list of names and ages. For example, when wanting to obtain a list of all females who are 50 years old, the syntax would read as follows:
      {IF}"{FIELD}gender~"="Female"                  <----First condition
                  {IF}{FIELD}age~>50~                        <----Second condition
                        {FIELD}name~, {FIELD}address~
                  {END IF}
      {END IF}

This procedure is called nesting. If the gender is not female the merge will automatically move on to the next record. If the gender is female, it will then compare to see if the female's age is over 50. Since the age field is a number, the field does not need to be in quotation marks. Also, since two {IF} statements were used two {END IF} statements are needed. If having trouble with the merge working correctly verify that there is a balance between the number of {IF}s and {END IF}s.

Shown below is an example of using the and command in a merge.
            {IF}"{FIELD}gender~"="Female"&"{FIELD}gender~"="Male"~
                  {FIELD}name~
                  {FIELD}address~
            {END IF}
This will print a list of all the males and the females.
{IF BLANK}
Customers using versions of WordPerfect before 5.1 were given the question mark (?) to use when wanting to close up a line if a field was blank. The question mark can still be used, but since it also sends a command to delete to the end of the line (thus eliminating the option of having additional text on the line) it makes it impossible to add additional text after the question mark on the same line. Because of this, the {IF BLANK} command was created. The syntax for this command would look something like the following:
{FIELD}1~{IF BLANK}2~ {FIELD}3~{ELSE} {FIELD}2~ {FIELD}3~{END IF}
This setup will always print fields 1, 2 and 3, but if field 2 is blank it will shorten the space and print just field one and three.

The syntax would look something like the following if the possibility of having two or more blank fields on one line arises:
{FIELD}1~ {IF BLANK}2~{FIELD}3~{ELSE}{FIELD}2~ {FIELD}3~{END IF}{IF BLANK}3~{FIELD}4~{ELSE} {FIELD}4~{END IF}

{IF NOT BLANK}
The {IF NOT BLANK} command can be very useful for users who want records if they are not blank. For example, a user can create a field that is only filled if the record is to be taken. If the record is desired a character can be placed within it. If the record is not desired the field is left blank.
The possible syntax would look something like the following:
      {IF NOT BLANK}include~{FIELD}name~
      {FIELD}address~{END IF}
This syntax would only print the person's name and address if the include field was filled. If the field was blank the program would skip over it to the next record.

When using the merge language there is often times more than one way to handle a situation. For example, the above statement for the include field could have been written as follows:
      {IF}"{FIELD}include~"="x"~{FIELD}name~
      {FIELD}address~{END IF}
Certain codes may take less space and work better for the individual user.
The examples given below were designed for customers who print the mailing address of one of their clients, unless it is blank. If it is blank, they want to print another field that contains the person's PO Box address. The syntax could use the {IF NOT BLANK} or the {IF BLANK} commands.

If using the {IF NOT BLANK} statement the syntax would look as follows:
      {IF NOT BLANK}mail~{FIELD}name~
      {FIELD}mail~{ELSE}{FIELD}name~
      {FIELD}postbox~{END IF}

If using the {IF BLANK} statement the syntax would look as follows:
      {FIELD}name~
      {FIELD}mail~{IF BLANK}mail~{FIELD}postbox~{END IF}

Which ever way is used be sure to include the {END IF} and tildes in the appropriate spots.

The example below can be used if wanted to print a variable number of labels of just one address. The paper size and type code would be in the initial settings like normal. This merge is designed to stop, ask the user for the number of labels and then make that many labels.

Insert the following codes in the primary file:
{TEXT}1~Enter number of times to repeat label: ~{COMMENT}
~{FOR}count~1~{VARIABLE}1~~1~{FIELD}1~
============(hard page)===============
{END FOR}

**Please note: In the above string of codes, you may not understand exactly how to get the {VARIABLE}1~ command in the middle of the string. The following steps show how to get the exact commands {FOR}count~1~{VARIABLE}1~~1~
      1.      Press Shift-F9, More (6)
      2.      Highlight the {FOR} command and press Enter
      3.      At the Enter Variable prompt, type count and press Enter
      4.      At the Enter Start prompt, type 1 and press Enter
      5.      At the Enter Stop prompt, press the Enter key
      6.      At the Enter Step prompt, type 1 and press Enter
      7.      Then, move your cursor between the two consecutive tildes to manually insert the {VARIABLE} command
      8.      Press Shift-F9, More (6), highlight the {VARIABLE} command, and press Enter. Then, at the Enter Variable prompt, type 1 and press Enter.

Insert the following codes in the secondary file:

Joe Smith
100 North West Rd
Orem, UT 93933{END FIELD}
{END RECORD}
============(hard page)==

Answer:

Details:


Product specifications, packaging, technical support and information (*Specifications*) refer to theUnited States retail English version only. Specifications for other versions may vary. All Specifications, claims, features, representations, and/or comparisons provided are correct to the best of our knowledge of the date of publication, but are subject to change without notice.OUR MAXIMUM AGGREGATE LIABILITY TO YOU AND THAT OF OUR DEALERS AND SUPPLIERS IS LIMITED. IT SHALL NOTEXCEED THE AMOUNT YOU PAID TO ACCESS THE INFORMATION. SEE LEGAL DISCLAIMER.