Input and Output Values Collection |
Collections are an Automation concept that allows a set of associated elements to be bundled together. The DataValues collection is defined as a class for use with Mathcad scripted components. A method and a property are provided to access to each of the elements in the collection. Each input element in the collection is itself an object of type DataValue, so values and dimensions of individual elements are accessed from those class properties.
Two DataValue collections are used as parameters the Exec event for all scripted components and controls. The first collection, Inputs, corresponds to the placeholders specified below the component, added when you right-click and select Add Input Value from the menu. The second collection, Outputs, corresponds to placeholders to the left of the definition symbol for the component. These two collections can have an arbitrary number of elements. Script authors may get or set the data for each input and output object in the collections.
These two collections are what allow a scripted component to interact with a Mathcad worksheet's calculations. By associating a component or 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 component that will use these worksheet variables, even if you access the value of the variable through Mathcad's Automation interface using GetValue or SetValue methods. It is also important that any variable name accessed through Automation is defined only once in the worksheet.
DataValue collections have one property, the read-only Count property, which can be used to query the total number of elements in the collection.
num = collDataValues.Count
DataValue collections have one method, the Item method, used to specify an individual element in the collection. The DataValue collection is zero-based, so the item numbers range from 0 to Count –1. The Item method is the default method for this object; this means that the method name can be omitted for languages that support it, in which case the default method is implied.
collDataValues.Item(integerindex), or, equivalently
collDataValues(integerindex)
'cycle through the collection, assigning
each item to val
for i=0 to Inputs.Count–1
val(i) = Inputs.Item(i)
'additional code...
next
or, since Item is the default property, the following is also valid:
'cycle through the collection, assigning
each item to val
for i=0 to Inputs.Count–1
val(i) = Inputs(i)
'additional code...
next