In the previous two posts (1st, 2nd) we looked at the capabilities of the SetAtRef function in the Shapesheet. This function along with the helper functions SetAtRefExpr and SetAtRefEval allows a shape designer to keep one or more cells synchronized. One important detail that was omitted was the fact that all three functions were introduced in Visio 2003.
Today we explore another Visio 2003 function that provides advanced shape behavior capabilities: the Bound function. Bound has two basic characteristics. First, the function takes any value and ensures that it lies within a set of boundary limits for the cell. If the value is within the boundary limits, Bound returns the value directly. If the value is not within the boundary limits, Bound returns the closest limit value. The second characteristic is that the Visio drawing window is aware of cells with the Bound formula and can visually enforce the boundary limits.
Here is the syntax for the Bound function:
BOUND (value, type, ignore, value1, value2 [,ignore(n), value1(n), value2(n),...])
value The current value being constrained.
type Whether the constraint is inclusive (0), exclusive (1), or disabled (2).
ignore TRUE to ignore the range; FALSE to constrain the value of the cell to the range.
value1 First value in a range.
value2 Second value in a range.
Let’s look at some examples to better understand this function. A Visio document with these examples is attached to this post for you use with Visio 2003. It is helpful to see firsthand how Visio enforces Bound as you manipulate the shape.
In the first example we want to keep the Width of the shape between 1 and 3 inches. This is an example of an inclusive type. As long as the incoming cell value is between 1 and 3 inches, the Bound function will return that value. If the incoming cell value is less than 1 inch, the function returns 1 inch. If the incoming cell value is greater than 3 inches, the function returns 3 inches. If you resize this shape in Visio, you will see that Visio acknowledges the Bound and prevents resizing outside the allowable range.
In this respect, Bound behaves similarly to SetAtRef. Any change made to the cell through the drawing window does not blast the formula already in the shape. Instead, Visio places the incoming cell value into the first argument of the Bound function. The first argument is in fact an implicit SetAtRefExpr function. We don’t show “SetAtRefExpr” to keep the Bound function syntax from getting too confusing, but that is what Visio is doing behind the scenes. Any shape Width that you attempt to set in the drawing window is pushed into the first argument.
The second example demonstrates the use of multiple ranges in Bound. The incoming cell value must fall within one of these ranges. The value1 and value2 arguments are set to the same value in this example to force the shape Width to a specific set of values. When working with multiple ranges, it may be desirable for some of the ranges to be disabled under specific conditions. The ignore argument prior to each range supports disabling of individual ranges.
The third example applies Bound to a control handle (you'll have to see this one in Visio). You can constrain the position of the control handle to stay within the bounding box of the shape.
The final example forces a control handle to remain outside the bounding box of a shape (you'll have to see this one in Visio). This is an example of an exclusive type. The control handle must not be within the range limits. There are some complications that must be addressed, however. It is okay for the horizontal position of the control handle to be within the limits if the vertical position is not within the limits. Likewise it is okay for the vertical position of the control handle to be within the limits if the horizontal position is not within the limits. This extra logic is placed into the ignore argument for the range limits. Note that these functions create a circular reference, but Visio can work through the circularity to produce the correct results.
Like SetAtRef, the Bound function opens a whole new set of opportunities for shape behavior. Shape designers can incorporate this behavior to create Smart Shapes with sensible restrictions on the way they can be manipulated.