Step 3: Add VB Script to REFERENCE_ID_COLOR.LBL

In this step, you will use the Label Template Editor to add VB script code to the new label template, REFERENCE_ID_COLOR.LBL, to set the background color based on the dimension color.

  1. Select File | Reporting | Edit | Label Template, and open REFERENCE_ID_COLOR.LBL. The label opens. It contains a GridControlObject with one row and one column. If you double-click on the cell, you will see an expression inside which reads:

=REF_ID:1

This means the label will display the ID of the reference feature.

  1. Right-click on the editor to display the Properties dialog box.

  2. Select GridControlObject1 from the list of objects.

  3. In the Properties dialog box, expand Events.

  4. Click [None] to the right of the EventReportData property. The VBS Mini-Editor appears. You may need to expand the VBS Mini Editor to be wider so that you can see the entire Sub statement toward the top.

You can see that the ReportData object is passed in. This is where PC-DMIS extracts information about passed in dimensions. For additional information on the ReportData object, see the "ReportData Object" topic in the PC-DMIS 2023.1 Object Library documentation. Also, if you need to reference the GridControlObject, you can use "This" as a shortcut to the object.

  1. Insert this code into the VBS Mini-Editor:

Dim I As Integer
Dim MaxIndex As Integer
Dim MaxDev As Double
Dim CurrentDev As Variant
Dim Dev As Variant
Dim PTol As Variant
Dim MTol As Variant
Dim iReturn As Boolean
 
' Initialize Max deviation and Max Index
MaxDev = 0.0
MaxIndex = 1
 
' Get the number of axes for this dimension
' 132 is the Dtype AXIS
Count = ReportData.GetCount(132)
 
' Loop through to find the largest deviation
' When the loop is complete, MaxIndex is the index to the
' largest deviation
For I = 1 to Count
    ' 340 is the Dtype DIM_DEVIATION
    CurrentDev = ABS(ReportData.GetValue(340, I))
    If CurrentDev > MaxDev Then
        MaxDev = CurrentDev
        MaxIndex = I
    End If
Next I
' Using MaxIndex, acquire that axes deviation, + Tol and - Tol
' 167 is Dtype F_PLUS_TOL; 168 is Dtype F_MINUS_TOL
Dev = ReportData.GetValue(340, MaxIndex)
PTol = ReportData.GetValue(167, MaxIndex)
MTol = ReportData.GetValue(168, MaxIndex)
 
' Use this information to adjust the background color of the grid cell
iReturn = This.SetCellBackgroundColor(0, 0, ReportData.GetTolColor(Dev,PTol,MTol))


Explanation of Code:

  1. Once you have added the code, click OK. The Mini-Editor checks for any syntax errors. If you have an error in your code, PC-DMIS displays a message at this time. If there aren't any errors, the VBS Mini-Editor closes.

  2. Select File | Save to save your new copy of REFERENCE_ID_COLOR.LBL.

  3. Select File | Close. This closes the Label Template Editor.

Goto Previous Tutorial StepGoto Next Tutorial Step