Equation tips for the Script Library
-
FsProcFuncSetEvent
is used for Copy Method scripts by default. - If an equation-specific function does not pass
Validation, and you are sure it is spelled correctly, then change the method to
FcProcFuncSetEq
. See the example. - When you alter the Method name, add a notation to the script of what you changed and why. Make it clear that this library can be used only for Equations, or whatever you changed it to.
Example
The
DailyValueRule
method can be called from the script
library to calculate equations. This nutritional example calculates the serving
size.
Option Strict Off
Imports System
Imports System.Diagnostics
Public Class NUTRITIONCALC
Private co As FcProcFuncSetEq
Public Sub New(ByRef context As FcProcFuncSetEq)
co = context
End Sub
'************************************************
Function dv_US(byref nutrient as string) As Double
dimstpval as string = co.Param(nutrient & "_SERV")
dim calcresult as double = -999
if co.isblank(stpval) = 0 then
dim dvrule as double = co.DailyValueRule(nutrient, "DV_US")
calcresult = cdbl(stpval) * cdbl(ssize) * 0.01
calcresult = math.round(calcresult,3)
end if
Return calcresult
End Function
End Class
The DVRule function can call a rule that does not exist or a parameter that is not on the rule. In this case, the function returns a 0. It does not return a null, a blank, or an error.
Daily values use the returned number as the divisor. You should verify that the number is greater than 0 before continuing with the math.