Controls > Advanced Controls > Inputs and Outputs for Scriptable Controls
Inputs and Outputs for Scriptable Controls
The inputs and outputs for any PTC Mathcad Prime scripted controls have the following properties. Controls can take any valid PTC Mathcad Prime data type as an input. This includes scalars, arrays, and strings or expressions that produce one of these values.
Indexing of input and output variables starts at 0. Inputs and outputs have associated properties and methods. Using outputs of one control as inputs to another, you can include multiple controls in the same worksheet. By associating a control with input and output values, you define its place in the calculation order of the worksheet, and notify it to recalculate when input values change, as well as notify the worksheet when to update the output values. It is therefore important that you assign input and output values to any control that will use these worksheet variables.
For advanced controls with inputs, it is recommended to define the output variable. If you leave an empty placeholder, values are not available to the control when opening the worksheet.
When the control does not have an output variable and the inputs are in array format, when the script accesses those inputs, an input validation is required. Add the line below to your script:
VBScript
If IsArray(Inputs(0).value) = False Then Exit Sub
JScript
if (!Inputs[0].Value.length) return;
Value
The Value property is used to access the real portion of the data. The row and col parameters are optional. If the row and col parameters are specified, a scalar value at the specified row or col is returned.
x = objDataValue.Value( [row, col])
objDataValue.Value( [row, col] ) = x
Input script in JScript:
var x = Inputs[0].Value[0][0]; //Accessing the 1st input, where the input is a matrix.
var y = Inputs[1].Value[0]; //Accessing the 2nd input, where the input is a vector.
var z = Inputs[2].Value; //Accessing the 3rd input, where the input is a variable.
Input script in VBscript:
x = Inputs(0).Value(0,0)
y = Inputs(1).Value(0)
z = Inputs(2).Value
Output script in JScript:
Outputs[0].Value[0][0] = x;
Output script in VBscript:
Outputs(0).Value(0,0) = x
Element
Description
x
The real portion of the data at this position.
row
The integer index of the selected row.
col
The integer index of the selected column.
When the Value property is used on the left side of an expression, the array does not automatically grow to fit the data. To avoid getting the error you must use the standard scripting language methodology to define the size. For example:
JScript:
//When using JScript, set the variable to array '[]' before assigning values.
Outputs[0].Value = [];
//In JS ES3 you can only use array of arrays.
Outputs[0].Value[0]=[0,0,0];
Outputs[0].Value[1]=[0,0,0];
Outputs[0].Value[2]=[0,0,1];
VBscript:
Dim out(2,2) ‘Set the array size. Notice this will create 3x3 dimensional array in VBscript.
Outputs(0).value=out
Outputs(0).value(2,2) = 1
The output of both cases is an array of three rows and three columns.
Rows and Cols
The Rows and Cols properties are read-only values that return the number of rows or columns in the control. You can use them to determine the dimensions of a vector or an array stored at a particular element at run-time.
JScript:
x = Inputs[0].Rows;
x = Inputs[0].Cols;
VBscript:
X = Inputs(0).Rows
X = Inputs(0).Cols
Element
Description
x
The integer number of rows or columns.
Was this helpful?