Variables

A variable is a resource that stores a numerical value and allows you to assign a name to that value. You can then use the variable name in place of the actual value in the equations that you create. You can also use variables in functions and/or as conditional output values in conditional blocks, logic gates and branch gates.

A variable starts with an assigned initial value, which may be fixed or varied during simulation in BlockSim. You can use variables:

Using Variables to Store Output Values in Event Analysis Flowcharts

You can use variables to hold numerical values passed to them during simulation. In event analysis flowcharts, the following blocks are able to store their output values in variables:

Depending on your choice in the When to Reset field of the variable's properties window, you can configure the variable to retain the value passed to it during simulation or reset the variable to its initial value at specific times. The options are:

When the simulations end, the variable always returns to its initial starting value unless you have selected Never Reset. If you wish to keep the value used during simulation, you can use a result storage block to store it.

Example

The following example demonstrates two things: a) how a variable may be used to store an output value and b) how a variable may be used in an equation.

In the following configuration, the first block calculates the gross profit from a sale, and then stores its output into a variable called "Profit." The conditional block determines whether the gross profit exceeds 500. If the output is true, the third block deducts the sale's commission from the profit, and overwrites the stored value with the new output.

The following picture shows the properties window of the variable called "Profit." The initial value of this variable is set to 0.

The following picture shows the Block Properties window of the first block in the example. The output of the equation is stored in the variable.

The following picture shows the Block Properties window of the third block in the flowchart. The equation shows that the commission is deducted from the existing value in the variable, and then the variable is overwritten with the new result. At the end of the simulation, the result storage block in the flowchart stores the final value of the variable, and then the variable resets to 0.

Related Topics and Links