#### Displaying a Variable's Value

PC-DMIS's reporting language lets you display a variable's value in your report by using the Variable() function. This function has the following syntax:

Variable(<varname>, [<optional command id or uid>])

The first parameter, coerced to a string type, represents the name of the variable. The second optional parameter can be used to solve for the variable's value relative to another command.

For example, suppose you this code in your part program:

ASSIGN/V1 = 2

F1 = FEAT/CIRCLE...

ASSIGN/V1 = F1.X

COMMENT/OPER,"Some comment text"

For the purposes of this example, assume that the comment has a unique ID or "UID" of 245.

Now consider the following examples with the code above:

=VARIABLE("V1") - If there are no other statements setting the value of V1 in the report then the value may be either 0, 2, or the same as the measured centroid x value of feature F1. It all depends on which commands have already executed at the point that the report expression is evaluated and which command is currently being processed for the report.

=VARIABLE("V1", "F1") - If this is the only feature named "F1" in the program, then the result of evaluating this expression should be 2 since V1 is assigned to 2 directly above feature F1.

=VARIABLE("V1", 245) - In this case, the UID is used; so the value of this expression on the report should be the same as F1.X.

Note: Individual cells of a GridControlObject cannot acquire a variable's value from the part program. In most cases you will need to use Text objects.

#### Variables and Headers

Normally, you cannot display a variable's value inside your report's file header because PC-DMIS evaluates the file header before executing statements in the part program. So, when the file header attempts to reference a variable that hasn't yet been created, PC-DMIS will display a zero value. However, some options do exist to get information from your part program into your header:

Option 1 - Use Trace Fields Instead of Variables | Use trace fields instead of variables in your part program to capture the information and then use the =TRACEFIELD() function inside the desired cell in the GridControlObject of the header's label template to reference it. Trace fields force the template to re-evaluate the report based on the new information causing the trace field to appear.

Advantages / Disadvantages

- Advantages - Relatively easy to set up.

- Disadvantages - You aren't actually using variables. Trace fields are used instead and have their own limitations.

Procedure

Step 1: Open the File_Header.lbl file in PC-DMIS and Modify the GridControlobject to hold another row of data.

1. In PC-DMIS access the label template editor (File | Reporting | Edit | Label Template) and open File_Header.lbl. It will appear in the label template editor. You will see the information is contained inside an object called a GridControlObject.

2. Select the GridControlObject and right-click on it. The Properties dialog box appears containing the properties making up the GridControlObject. Add another row, by changing NumRows to 3 and pressing TAB. Notice that the background isn't tall enough to support the added row.

3. From the drop down list on the Properties dialog box, select TheFrame/TheView and change the Height property to 100 and press TAB to accept the change.

Step 2: Add a report expression into the GridControlObject to accept a trace field's information

1. Select the GridControlObject again.

2. If the handles (green boxes) do not yet include the newly added row, drag the green handles downward until they do.

3. Double-click to make the GridControlObject "active". This shows all the behind-the-scenes expressions.

4. Select the cell that will hold the trace field's value and type: =TRACEFIELD(1) and then press TAB. This expression tells PC-DMIS to put the data for the first trace field in that cell. For example, if you wanted the second trace field's data, you would use =TRACEFIELD(2). (See the attached image file below.)

5. Play around with the cells and format them as desired. The best way to do this is to select one or more cells within the grid and then right-click on it. The Grid Properties dialog box appears.

6. Deactivate the GridControlObject by clicking outside of it.

7. Save your changes.

Step 3: Test your changes.

1. Execute your part program.

2. Access the Report window (View | Report Window).

3. Click the Redraw the Report icon on the Reporting window's toolbar.

4. The trace field's info should now appear in the header.

Option 2 - Embed the Report Template | Embed the report template into your part program sometime after the ASSIGN statements have been defined, and then send the variable's value to the label template as a parameter. Add additional rows or cells as needed, and on top of the added cells, add and size a Text object for each variable you want to display. Finally, modify the Text property through a parameter of the REPORT/TEMPLATE command, like this:

ASSIGN/V1="A String Value to Pass"

CS1 =REPORT/TEMPLATE, FILENAME= TEXTONLY.RTP, AUTOPRINT=NO, Section=-1

PARAM/TEXT1.TEXT=V1

PARAM/=

ENDREPORT/

Because the label template is merged into the report template you can modify certain parameters on the label template by referencing the report template in the above fashion.

Advantages / Disadvantages

- Advantages - Variables will now appear in your final report's header.

- Disadvantages - Somewhat difficult to setup as you will need to add a Text objects into your label template in addition to the code to embed the report template into the part program. The main disadvantage to this approach, however, is that the report will be generated twice one after the other. Once from PC-DMIS's default functionality and again from the embedded REPORT/TEMPLATE code block.

Option 3 - Put Header Information Directly into Report | Instead of using a report template that refers to an external label template for the header, such as File_Header.lbl, recreate the GridControlObject from the header's label template directly inside your report template. Add additional rows or cells as needed, and on top of the added cells, add and size a Text object for each variable you want to display. Then for each Text object use the =VARIABLE() function to pull in the variable information. For example, =VARIABLE("V1").

Make these remaining modifications inside the report template:

1. In the TextReportObject change the rules so that the header label isn't used.

2. Set these properties for the current section, Section1:

Command Set = All Commands

Maximum Number of Pages = 1

2. Add a second section, Section2, and give it a TextReportObject as well, again changing its rules so that a header label isn't used.

3. Set these properties for Section2:

Command Set = Continue From Previous Section

Maximum Number of Pages = 0 (meaning there is no maximum)

Advantages / Disadvantages

- Advantages - Variables will now appear in your final report's header.

- Disadvantages - Somewhat difficult to set up since you have to recreate the GridControlObject inside the report template, add Text objects for each variable, and add an additional report section. Additionally, any editing done to the report, such as turning on "Show Feature" or changing Dimensions to "Out of tolerance Only", needs to be done twice, once for page 1 (first section) and once for the other pages (section 2).

Option 4 - Use a Generic Feature to Force Report Regeneration | This option uses an empty Generic feature to force the label template to re-evaluate the report and pull in needed variables values into your final report. In your part program, create an empty Generic feature and give it a descriptive name such as:

REPORTHEADER=GENERIC/NONE,DEPENDENT,CARTESIAN,OUT,$

Next, modify the header label template, adding additional cells as needed to the GridControlObject, and then on top of the added cells, add and size a Text object for each variable you want to display. Now set the Text property for each Text object to use the =VARIABLE() function to pull in the variable information. In this option, however, you need to refer to the generic feature by using use the extra parameter in the =VARIABLE() function. For example, =VARIABLE("V1","REPORTHEADER")

Advantages / Disadvantages

- Advantages - Probably the most versatile approach. Variables will now appear in your final report's header. You will not need to edit the final report twice as in Option 2

- Disadvantages - Somewhat difficult to set up since you will need to include an empty Generic feature in your part program and add Text objects for each variable inside the label template.