Sometimes you may need to generate or calculate a value that is not available from the Statistics or Columns in the Retrieval Settings for the report. One method you can use to calculate values is by using Custom Code.
In this example, we will create a report where the Retrieval Settings include the Column for "Lot". This means that the lot number from each retrieved data record will be provided to the report. Then we will use custom code to count the number of unique Lot numbers that were retrieved for the report, and we will show this number (the count) on the report.
Create a new report – either an SPC report or a DMS report.
On the Part Number tab, select one standard or process. (You can later edit the report for multiple standards/processes if desired.)
On the Columns tab, choose the traceability field for which you want to count the unique values (such as Lot):
You can also choose any other data columns that you want to provide to the report.
Click Design Report to proceed to the design window for this report.
If you expand the GainSeeker\DataDetail dataset, you should see all of the data columns you chose on the Columns tab – including the traceability field for which you want to count the unique values.
Click the button and then paste the following text into the upper part of your screen:
public function SumParts(values as System.Collections.ArrayList) as double
dim i as integer
dim totTrace as integer
dim psTrace as string, psTemp as string
totTrace = 0
for i = 0 to values.Count-1
psTemp = values(i) & "|"
if instr(psTrace, psTemp) = 0 then
psTrace = psTrace & psTemp
totTrace = totTrace + 1
Your screen will now look something like this:
To use this custom code on your report:
Click the button.
From the GainSeeker\DataDetail dataset, drag the Lot column and drop it on the body of your report:
You may also want to drag the textbox wider, as we'll have to add more to call the custom code.
Because the SumParts code that we pasted expects us to send it an array of traceability values, we can convert the default value for this textbox from the first value to the array of values. We do this by using the ToArray method, as shown below:
Now to send this array to the SumParts code, we enclose this entire ToArray(...) command in parentheses and add code.SumParts to the front, like so:
Now we need to save the report, view the results, and make sure the results match the data.
To save the report, click the button. Alternately, you may click the File menu and then click Save Report.
To view the report, click the button or click the File menu and then click View Report.
Your report will probably contain only a number – one that reflects the number of unique values from the traceability column you specified.
If you want to check this number, you can do one of the following:
For SPC data:
Use the SPC Charts and Reports module to create a control chart for the same data you retrieved on the report.
Right-click the chart and choose Group Data, then group and sort the data by the traceability field for which you are counting unique values.
Count the data groups, or else right-click the grouped chart and then choose Control Limit Legend.
Either way, the number of groups you find here should match the number reported by your custom code.
For DMS data:
Use the DMS Charts and Reports module to draw a Pareto chart for the same data you retrieved on the report, with the Pareto bars sorted by the traceability field for which you are counting unique values.
Right-click the chart and then click Display Options. Select the Show bars with no Defects check box, and then click OK.
Count the Pareto bars. This should match the number reported by your custom code.
You could modify this code to use it with data point values or specification limits. In that case, you would need to convert the string value into a double using cdbl(values[i]) if you want to treat the data set as numbers.
For some operations, it will be easier to use the built-in statistics, e.g. Sum values, because the GainSeeker statistics automatically exclude data values that are not set. If you perform the sum yourself in custom code, you will need to verify that values[i] contains a valid number before trying to convert it to a double using cdbl (missing data values are blank/empty strings). Note that when the upper and lower specification limits are not set, their value is "NONE".