WinVask -  Faktura

How To: Conditionally Print Text

How To: Conditionally Print Text

Previous topic Next topic  

How To: Conditionally Print Text

Previous topic Next topic  

 

Problem: Some of the information inside the database, when printed, is empty due to the way it was inputted by the user. When the report is printed this results in blank spaces on the report where the information would/should have been printed. For example, the fictional  database program has a database field defined for the customer's phone number - the customer either didn't have a telephone, didn't provide the information to your sales clerk, or your sales clerk forgot to type it into the application.

 

Solution:  By using the CHOOSE() logical operator you can test for a condition and tell the Report Builder how to handle the result.

 

Example 1

For the above problem (empty telephone number) you need to check the length of the database field; if it is less than seven characters in length then you know the telephone number is bad or empty. To check the length of a database field you need the CLIP() and LEN() functions; CLIP() is used to remove any blank spaces from the end of the database field value, and LEN() will return the exact number of characters that contain an alphanumeric value (A-Z, 0-9). The Frame Properties Window entry field would resemble this:

 

=CHOOSE( LEN(CLIP(INV:PhoneNumber)) < 7, 'Unknown', INV:PhoneNumber)

 

Example 2

If the database field named INV:VendorNumber contains a zero you want the text "unknown" printed on the report page instead of the number zero; if the INV:VendorNumber contained a value higher than zero you want to print the Vendor's Name. The Frame Properties Window entry field would resemble this:

 

='T O T A L for vendor '& CHOOSE(INV:VendorNumber=0,'unknown',VEN:VendorName)