7.4

Table Of Contents
l Defining program logic As for any coding, when you write programs in PlanetPress Talk you should work through
the logic of the program you intend to create before you start coding. This ensures the program accomplishes what you
intend it to accomplish, and makes the coding more straightforward. It can also result in insights into different ways of
accomplishing the same task, or raise issues that were not immediately apparent.
l Test If you are writing a complicated script, it is recommended you use the PlanetPress Talk Editor, and test your code
regularly as you develop it. This helps you discover and solve any problems early on in the development process.
l Simplicity As in any programming language, aim for both simplicity and clarity in your scripts.
l Using mathematical operators Enclose mathematical operators in parentheses ( ) to make your code easier to
read and therefore easier to maintain.
l Performing complex calculations PlanetPress Talk limits its precision to 1/1000 to optimize speed and thus is not
designed to handle complex mathematical computations. If you require greater precision you should perform the cal-
culation outside PlanetPress Talk and include the result in the input data for your document.
l CasePlanetPress Talk is case-insensitive. It is good programming practice to establish case conventions as it enhances
the readability of the resulting code. It is recommended that you use lower case for all PlanetPress Talk reserved
words (names of system variables, operators, and commands) as this is the default case convention of the PlanetPress
Talk Editor.
l Indent Use indents to visually represent the structure of the script. For example, indent the commands a loop struc-
ture encloses to make it apparent where the loop begins and ends.
l Comments Include meaningful comments in your code to make it easier to read and maintain.
Code Samples
This section presents short samples of PlanetPress Talk code that may be useful, and that may also stimulate your imagination
for the ways in which you can use PlanetPress Talk in your documents. Consult the PlanetPress Talk Language Ref-
erence for help understanding specific commands.
l "Print a variable number of copies of a page based on a value in the datastream" (page 239)
l "Store two lines of input data on one line of the data page" (page 240)
l "Print a page n-up" (page n)
l "Print a line of text on odd-numbered pages" (page 241)
l "Determine the proper page to print based on the width of the data in the data page" (page 241)
Print a variable number of copies of a page based on a value in the datastream
This sample prints a variable number of copies of a page based on an integer value in the data stream. It uses a global integer
variable &nbPage that is initialized to 0, and subsequently set to the value of the data that appears on line 1, columns 1
through 2 of the data page.
The document for which it was written uses two pages: DATA and RUNPAGE. DATA is an overlay page that contains all of the
data selections for the document. RUNPAGE is a runpage and the code that appears here is in a PlanetPress Talk object on
RUNPAGE.
% ====================================================
% PRINT A VARIABLE NUMBER OF COPIES OF A PAGE BASED ON
% A VALUE IN THE DATA STREAM
% ====================================================
if(ne(&printermode,0))
set(&nbPage,strtoint(@(1,1,2)))
define(&it,integer,0)
©2010 Objectif Lune Inc - 239 -