Example of error for Context.ReturnValue with Option Strict On
In equations, Context.ReturnValue
is used to return the value to the parameter that is associated with the equation. The data type of the return value is a string because:
- the return value must be used for every type of parameter (string, numeric, Boolean, etc)
- the actual data type of a parameter is a string
What has been said about ReturnValue
also holds true for each of the parameter value functions (param
, tparam
, paramitem
, tparamitem
, valparam
). These functions return a string value.
The data type of the parameter value functions is a string; the scripting engine interprets “param(“DENSITY”) + param(“FAT”)”
to mean that you intend to concatenate two strings. To treat these values as numbers, you must explicitly convert them to a numeric data type with CDbl
.
This example shows that validation fails with Strict ON
and how it can be corrected. The original param
function returns a String
value which cannot be converted to the required Double
.
Context.ReturnValue = param("DENSITY") + param("FAT")
This error is displayed.
Error of severity 0 on line 6: Option Strict On disallows implicit
conversions from ‘String’ to ‘Double’.
The corrected function performs a conversion to a DOUBLE
.
Context.ReturnValue = CDbl(param("DENSITY")) + CDbl(param("FAT"))