User Tools

Site Tools


examples

Examples

The examples in this section are designed to provide an overview of the use of PrintList Pro and the basic commands.

You may also wish to examine the PrintList Pro demo, for more examples on the various PrintList Pro capabilities.

Example 1 — One record current selection

Print a list of information (First name, Last name, Salary, City, State, Zip, Country) contained in a series of seven arrays. Show column headers and print dividing lines between the columns. Do not print dividing lines between the rows.

PRINT SELECTION is used to print PrintList Pro plug-in objects. It is important therefore, that you carefully control the current selection, since a PrintList Pro plug-in object will print once for each record in the current selection.

This example illustrates a situation where the PrintList Pro object is to be printed once, so we can use the PRINT RECORD command regardless of the current selection.

First we need to create the layout and draw the PrintList Pro plug-in object. We’ll name the object eList.

Our layout now looks something like this:

The project method which controls the printing is:

 ALL RECORDS([Layouts])
 OUTPUT FORM([Layouts];"Example 1")
 PRINT RECORD([Layouts])

We’ll use the On Printing Detail event to configure our PrintList Pro area.

Here is the PrintList Pro area's object method:

If (Form event=On Printing Detail)
 ALL RECORDS([People])
 // Create the arrays from the data
 SELECTION TO ARRAY([People]First Name;aFname;[People]Last Name;aLname;[People]Salary;\
 aSalary;[People]City;aCity;[People]State;aState;[People]Zip;aZip;[People]Country;aCountry)
 $plErr:=PL_SetArraysNam (eList;1;7;"aFname";"aLname";"aSalary";"aCity";"aState";"aZip";\
 "aCountry") // set the arrays
 If ($plErr=0)
  PL_SetHdrOpts(eList;2;0) // print headers on all pages
  PL_SetHeaders(eList;1;7;"First Name";"Last Name";"Salary";"City";"State";"Zip";"Country")
  // apply to all headers: Lucida Grande 10 point bold
  PL_SetHdrStyle(eList;0;"Lucida Grande";10;1)
  PL_SetStyle(eList;0;"Lucida Grande";9;0) // apply to all columns: Lucida Grande 9 point plain
  // print only column dividers: solid gray hairlines
  PL_SetDividers (eList;25;"Black";"Gray";0;0;"";"";0)
  // sort column 2 (Last name) in descending order
  PL_SetSort (eList;-2)
 End if
End if

The printed layout will appear as shown below:

Example 2 — Multiple record current selection

Print a list of company names, showing all the people who work for each company. This example will illustrate the use of PrintList Pro with multiple records in the current selection.

For purposes of illustration, the company names will be printed directly from the [Companies] table, and the [People] information will be printed from a series of arrays using PrintList Pro.

Create the layout and draw the PrintList Pro plug-in object. This process is substantially the same as that explained in the first example, with one exception — we are going to include a field directly on the layout which will print information alongside the PrintList Pro object.

Our layout is illustrated below:

The only difference between this example and Example 1 is that we are printing out multiple records.

Since the PrintList Pro commands are executed in the On Printing Detail event of the PRINT SELECTION command we can change the People arrays “on the fly”.

The [Companies] file is in a One-to-Many relationship with the [People] file, and the links are automatic.

As each [Companies] record is printed a new selection of [People] records is created.

This [People] selection is stored in arrays and printed.

The controlling project method is:

  ALL RECORDS([Companies])
  OUTPUT FORM([Companies];"Example 2")
  PRINT SELECTION([Companies])

The PrintList Pro area's object method is:

If (Form event=On Printing Detail)
 // Create the arrays - the current selection of [People] changes with each new record
 SELECTION TO ARRAY([People]First Name;aFname;[People]Last Name;aLname;[People]Salary; aSalary)
 $plErr:=PL_SetArraysNam(eList;1;3;"aFname";"aLname";"aSalary") // set the arrays
 If ($plErr=0)
  PL_SetHdrOpts(eList;1;0) // print headers at the top of the area only
  PL_SetHeaders(eList;1;3;"First Name";"Last Name";"Salary") // set headers
  // apply to all headers: Lucida Grande 10 point bold
  PL_SetHdrStyle(eList;0;"Lucida Grande";10;1)
  PL_SetStyle(eList;0;"Lucida Grande";9;0) // apply to all columns: Lucida Grande 9 point plain
  // format column 3, right justified header and column
  PL_SetFormat (eList;3;"$###,###,###.00";3;3)
  // solid black hairline frame/hdr line
  PL_SetFrame (eList;0.25;"Black";"Black";0;0.25;"Black";"Black";0)
  End if
End if

A portion of our resulting printout appears below:

Example 3 — Adding a total line to the list

Print the same list of company names and people as Example 2 and add a total line after the end of each list of people. The total line will contain a sum of the salaries for all the people working for that company.

A total line requires us to use PrintList Pro’s Break Level commands.

While most break levels require the list to be sorted, a total line is the exception. The total line is is configured by passing 0 for the break level parameter.

The object method for the PrintList Pro area in Example 2 has been modified to include the Break Level calls needed as shown below:

 If (Form event=On Printing Detail)
  // Create the arrays - The current selection of [People] changes with each new record
  SELECTION TO ARRAY([People]First Name;aFname;[People]Last Name;aLname;[People]Salary; aSalary)
  $plErr:=PL_SetArraysNam(eList;1;3;"aFname";"aLname";"aSalary") // set the arrays
  If ($plErr=0)
   PL_SetHdrOpts(eList;1;0) // print headers at the top of the area only
   PL_SetHeaders(eList;1;3;"First Name";"Last Name";"Salary") // set headers
   // apply to all headers: Lucida Grande 10 point bold
   PL_SetHdrStyle(eList;0;"Lucida Grande";10;1)
   PL_SetStyle(eList;0;"Lucida Grande";9;0) // apply to all columns: Lucida Grande 9 point plain
   // format column 3, right justified header and column
   PL_SetFormat(eList;3;"$###,###,###.00";3;3) // solid black hairline frame/hdr line
   PL_SetFrame (eList;0.25;"Black";"Black";0;0.25;"Black";"Black";0)
   PL_SetWidths(eList;1;3;80;80;100) // set the column widths
   // Configure the total line
   PL_SetBrkText(eList;0;3;"\Sum";0;0) // calculate the sum in the total line
   PL_SetBrkHeight(eList;0;1;4) // add some padding to the total line
   PL_SetBrkColOpt(eList;0;3;0;0.25;"Black";"Black";0) // draw a line above the total
  End if
 End if

The total line now appears in the list as is shown below:

Example 4 — Break Level Processing

Print the same list of information shown in Example 1 and add some break level information for all the people in the same city. The break will show a sum, minimum, average, maximum and standard deviation of the people’s salaries in each city.

Labels for each of the calculations will be printed in the adjacent column to salary. The break will also show the number of people in the city and the city name.

A custom calculation is included along with the other calculations to calculate an end of year bonus based on 5% of the average salary.

The list is sorted by country, state, city and last name. This allows the suppression of repeated values for each of these columns. In order to set break information for the city, we must configure break level 3 because the city array is 3rd in the sort order.

Each of the calculations mentioned will be printed on a separate line, so the height of the break is set to 6 lines. Carriage returns are inserted between the labels and calculations so that each will start on a new line.

The code for the callback function follows the object method to the PrintList Pro object. In addition, two header lines are shown to demonstrate the ability for multiple lines in a header.

The object method for the PrintList Pro plug-in area in Example 1 has been modified to include the Break Level calls needed as shown below:

 If (Form event=On Printing Detail)
  // Create the arrays from the data
  ALL RECORDS([People])
  SELECTION TO ARRAY([People]First Name;aFname;[People]Last Name;aLname;[People]Salary;\ aSalary
  [People]City;aCity;[People]State;;[People]Country;aCountry)
  // Set the arrays
  $plErr:=PL_SetArraysNam (eList;1;6;"aFname";"aLname";"aSalary";"aCity";"aState"; "aCountry")
  If ($plErr=0)
   PL_SetHdrOpts(eList;2;0) // print headers on all pages
   PL_SetHeight(eList;2;4;1;0) // 2 hdr lines, 4 hdr pad, 1 row line, 2 row pad
   PL_SetHeaders(eList;1;6;"First Name";"Last Name";"Salary";"City";"State";"Country")
   PL_SetHdrStyle(eList;0;"Lucida Grande";10;1) // all headers: Lucida Grande 10 point bold
   PL_SetStyle(eList;0;"Lucida Grande";9;0) // all columns: Lucida Grande 9 point plain
   PL_SetFormat(eList;3;"$###,###,###.00";3;3) // format column 3, right justified header and column
   PL_SetFrame(eList;0.25;"Black";"Black";0;0.25;"Black";"Black";0) // print solid black hairline frame
   PL_SetWidths(eList;1;6;76;80;89;79;80;48) // set the column widths
   PL_SetBackClr(eList;"Light Gray";0;"White";0)
   // Sort by Country (descending), State, City, and Last Name (descending)
   PL_SetSort (eList;-6;5;4;-2)
   // Break level Configuration
   PL_SetRepeatVal(eList;0;1) // suppress repeating values in all columns
   PL_SetBrkFunc(eList;"Break Function") // set the callback function
   PL_SetBrkRowDiv(eList;0.25;"Black";"Black";0) // print a Break/Row divider
   // Configure break level 3, city
   PL_SetBrkHeight(eList;3;6;4) // print 6 lines for break level 3
   // Print the calculation labels in the column to the left of the salaries
   PL_SetBrkText (eList;3;2;"Sum\rAverage\rMinimum\rMaximum\rStandard Dev\rBonus";0;3)
   PL_SetBrkStyle(eList;3;2;"Lucida Grande";9;1) // make the labels bold
   // Print the Sum, Minimum, Average, Maximum, Standard Deviation and Bonus for salaries
   PL_SetBrkText (eList;3;3;"\\Sum\r\\Minimum\r\\Average\r\\Maximum\r\\Dev\r\\Function";0;0)
   // Show the number of people in this city
   PL_SetBrkText(eList;3;5;"\r\\Count people in \\BreakValue";1;2)
   PL_SetBrkStyle(eList;3;5;"Lucida Grande";10;3) // make the city count info 10 points bold
   PL_SetBrkColOpt(eList;3;3;0;0.25;"Black";"Black";0) // print a subtotal line in the salary column
   End if
 End if

The Break Function callback method for the “Bonus” custom calculation is as follows:

 C_LONGINT ($1;$2) // break level, column
 C_TEXT ($2;$3) // column format
 C_LONGINT($4;$5) // start row, end row
 C_TEXT($0) // custom calculation result to print
 C_LONGINT($i;$count)
 C_REAL($result;$average)
 // Calculate the average
 For ($i;$4;$5)
  $result:=$result+aSalary{$i}
 End for
 $count:=$5-$4+1
 $average:=$result/$count
 $result:=Int($average*0,05) // 5% rounded
 $0:=String($result;$3)

Here is a sample of the list containing the breaks:

Example 5 — Computed Breaks

Computed breaks are a powerful array utility module, which does not require printing.

The demonstration database includes an example under PrintList Pro > Configuration options… Check the “Compute breaks without print” box:

then click the “Print With PrintList Pro” button:

We will perform a similar action, using the same arrays as in Example 4, then call PL_ProcessArrays and PL_GetBreakValue to retrieve the results and build a break summary.

We will create a text variable containing all break results without printing anything, then copy it into the pasteboard. We could also display the text variable like in the demonstration database, or use it otherwise.

 C_TEXT(vBrkComputeResult)
 ARRAY TEXT(TbreakText_R;0)
 C_LONGINT($i)
 // Create the arrays from the data
 ALL RECORDS([People])
 SELECTION TO ARRAY([People]First Name;aFname;[People]Last Name;aLname;[People]Salary;\
 aSalary;[People]City;aCity;[People]State;aState;[People]Country;aCountry)
 // Sort by Country (descending), State, City, and Last Name (descending)
 MULTI SORT ARRAY(aCountry;<;aState;>;aCity;>;aLname;<;aFname;aSalary)
 // Declare the "data" array pointing on the actual arrays on which to perform calculations in our callback
 // (we include all arrays in case we'll need them someday, even though we will only use aSalary here)
 ARRAY POINTER($dataArrays;0)
 APPEND TO ARRAY($dataArrays;->aCountry)
 APPEND TO ARRAY($dataArrays;->aState)
 APPEND TO ARRAY($dataArrays;->aCity)
 APPEND TO ARRAY($dataArrays;->aLname)
 APPEND TO ARRAY($dataArrays;->aFname)
 APPEND TO ARRAY($dataArrays;->aSalary)
 // Declare the "break" array pointing on the arrays where to catch breaks in our callback
 // according to our MULTI SORT ARRAY above (sorted arrays)
 ARRAY POINTER($breakArrays;0)
 APPEND TO ARRAY($breakArrays;->aCountry)
 APPEND TO ARRAY($breakArrays;->aState)
 APPEND TO ARRAY($breakArrays;->aCity)
 APPEND TO ARRAY($breakArrays;->aLname)
 // Now we process the arrays using the "PlpComputeBreak" project method for computing
 If (PL_ProcessArrays ("PlpComputeBreak";$breakArrays;$dataArrays;0)=0)
  // 4th parameter is 0 for each break or 1 for each row
  // Now TbreakText_R has been populated by PlpComputeBreak: concatenate breaks into a text variable
  vBrkComputeResult:=""
  For ($i;1;Size of array(TbreakText_R))
   vBrkComputeResult:=vBrkComputeResult+TbreakText_R{$i}+Char(Carriage return)
  End for
  SET TEXT TO PASTEBOARD(vBrkComputeResult) // or do something else with vBrkComputeResult
 End if
 

Here is our PlpComputeBreak callback method.

 C_LONGINT($1;$2;$3) // handle, row, break level ($breakArrays)
 C_LONGINT($dataArray) // position of the array to feed computed break in $dataArrays
  // from the calling method (third parameter to PL_ProcessArrays)
 C_TEXT($format;$breakText)
 If ($3>=0) // is it a break
  $dataArray:=6 // aSalary
  $format:="$###,###,###.00"
  Case of
   : ($3=1) // break on aCountry
   : ($3=2) // break on aState
   : ($3=3) // break on aCity
    // $breakText:="Hello, I am the break at level "+String($3)+" after row "+String($2) \
    // +(Char(Carriage return)*2) // we could do this to use $2
    // Concatenate the text for the current break
    $breakText:=""
    $breakText:=$breakText+"There are "+String(PL_GetBreakValue ($1;$dataArray;5)) +" people in"\
     +aCity{$2-1}+(Char(Carriage return)*2)
    $breakText:=$breakText+"Sum: "+String(PL_GetBreakValue ($1;$dataArray;1);$format)\
     +Char(Carriage return)
    $breakText:=$breakText+"Minimum: "+String(PL_GetBreakValue ($1;$dataArray;2);$format)\
     +Char(Carriage return)
    $breakText:=$breakText+"Average: "+String(PL_GetBreakValue ($1;$dataArray;3);$format)\
     +Char(Carriage return)
    $breakText:=$breakText+"Maximum: "+String(PL_GetBreakValue ($1;$dataArray;4); $format)\
     +Char(Carriage return)
    $breakText:=$breakText+"Standard Dev: "+String(PL_GetBreakValue ($1;$dataArray;7);$format)\
     +Char(Carriage return)
    // We perform the 5% calculation right here:
    $breakText:=$breakText+"Bonus:"+String(Round(PL_GetBreakValue ($1;$dataArray;3)*0,05;0);\
     $format)+Char(Carriage return)
    $breakText:=$breakText+"---------------"+Char(Carriage return)
    APPEND TO ARRAY(TbreakText_R;$breakText)
   : ($3=4) // break on last name
  End case
 Else // this is a row because $3 < 0
  // do something
 End if

Here is the resulting text:

There are 4 people in Podunk

Sum: $168 092,54

Minimum: $23 275,98

Average: $42 023,13

Maximum: $60 956,00

Standard Dev: $13 325,83

Bonus: $2 101,00


There are 3 people in Phoenix

Sum: $104 428,80

Minimum: $20 416,34

Average: $34 809,60

Maximum: $52 230,08

Standard Dev: $13 163,11

Bonus: $1 740,00


There are 6 people in Cupertino

Sum: $295 862,00

Minimum: $24 963,54

Average: $49 310,33

Maximum: $70 962,78

Standard Dev: $17 654,11

Bonus: $2 466,00


examples.txt · Last modified: 2017/06/27 14:09 by plp_admin