Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: RhesusMinus on August 09, 2011, 12:36:10 PM

Title: Best practise for formulas
Post by: RhesusMinus on August 09, 2011, 12:36:10 PM
Hi there.

What is the best practise for using formulas in the shape sheet.

Let's say I have a user variable in the document that can be value 100, 250 or 700.

And I want a give shapes width to reflect the document setting.

I see two solutions.

a) Put this in the shapes width formula: =IF(TheDoc!User.MyValue=100, 120 mm, IF(TheDoc!User.MyValue=250,289 mm,713 mm))

b) Create a user variable in the shape, named MyValue, with the formula =TheDoc!User.MyValue
    and put this in the shapes width formula: =IF(User.MyValue=100, 120 mm, IF(User.MyValue=250,289 mm, 713 mm))


Do Visio use more time calculating references going out of the shape rather than inside the shape?

For this example there is no problem, with only 3 possible values.. however.. if you multiply this many times, there might be a performance issue...

THL
Title: Re: Best practise for formulas
Post by: Jumpy on August 09, 2011, 02:29:54 PM
AFAIK as the general rule u should avoid multiple dependency:
User.A  = 4
User.B = User.A
User.C = User.B
Uder.D = User.C

So I think your a) is better.

But the many If-Statements is not good practice, because if you get another (4th) value, you have to adjust all If-Statemens. It is better to use lists and work with the INDEX- and the LOOKUP-functions.
In Doc:
User.MyValue = 100
User.MyValueList = "100;250;700"
eventually: User.MyValueIndex = LOOKUP(User.MyValue,User.MyValueList)

In Shape
User.MyWidthList = "120 mm;289 mm;713 mm"
Width = INDEX(LOOKUP(TheDoc!User.MyValue,TheDoc!User.MyValueList),User.MyWidthList)
or if you use the eventually version in TheDoc:
Width = INDEX(TheDoc!User.MyValueIndex,User.MyWidthList)

P.S.: Don't have Visio at the moment. May probably have confused Index and Lookup, so you have to eventually exchange them.
Title: Re: Best practise for formulas
Post by: wapperdude on August 09, 2011, 02:47:51 PM
If you put the formula in the Width cell, you will have to enclose it with the Guard function, guard(your formula).  Otherwise, when the user changes the size, it will clobber the formula.

Wapperdude