Set up an Analyte Formulae Script

Analyte formulae are C# scripts used to calculate the final result of an analyte when quality is monitored for material being transferred across process flows and discrete unit movements.

Example: Analyte Formula for Fe:MgO

The following script calculates the ratio of iron to magnesium oxide. It presumes that the Fe and MgO analytes are already set up.

Copy
public class FeMgO_Calc : IAnalyteFormula
{
    /// <summary>
    /// Gets the name that will appear in the user interface for this formula script.
    /// </summary>
    public string FormulaName
    {
        get 
        {
            return "Fe:MgO Calc";
        }
    }
    public NullableDouble CalculateValue(CalcStockBalanceAnalyteList analytes)
    {
        // Get the value of the analyte based on the analyte's alias1
        NullableDouble feValue = analytes["Fe", true];
        NullableDouble mgoValue = analytes["MgO", true];

        // Check to make sure that none of the analyte values are null
        if (!feValue.IsNull && !mgoValue.IsNull)
        {
            // Perform the calculation
            return feValue.Value / mgoValue.Value;
        }
        else
        {
            // If any of the analyte values were null then return NullableDouble.Null
            return NullableDouble.Null;
        }
    }
}

Security Note: You need the Allow script maintenance and Allow the user to maintain analyte formulae user group security rights in the Scripting user group security rights group for this activity.

Activity Steps

  1. Open the Analyte Formula (script editor).

    The Scripting Ribbon Tab displays.

  2. Edit the C# script.
  3. Append the public class code after any other public classes in the analyte formula code.
  4. Ensure that script references are selected:
    1. Note the DLLs that are referenced in the script. The DLLs are listed at the top of the script, after the word "using".
    2. Select the References tab.
    3. Select the required DLLs.
  5. Click the Build icon on the Scripting ribbon tab to compile the script.
  6. Click the Save icon on the Scripting ribbon tab.