String Comparison in ShapeSheet IF Statement Not Working?

Started by karininwinnipeg, January 19, 2015, 06:40:30 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

karininwinnipeg

Hi everyone.
I'm trying to get an org chart shape to adjust its fill color according to a value in a custom field.
It seems to work but only kind of. It might be my syntax.
I've selected a shape, typed the following into the Fill Format section of the ShapeSheet, in the FillBkgd property: =IF(Prop.Department="HR",RGB(255,0,0),RGB(255,255,255))
So in theory, if I type "HR" into the Department field, the shape should be red, if it's anything else, should be white.
:-\
See pic.
What am I missing?

Visio Guy

Hi Karin,

In the ShapeSheet, "HR" = 0, "Karin" = 0, "Chris" = 0. That's what they evaluate to. To test strings, you have to use the STRSAME function.

So:

IF(STRSAME(Prop.Department,"HR"),RGB(255,0,0),RGB(255,255,255))

STRSAME has a third argument for case-sensitivity as well.

EVERYONE misses this, so don't worry about it. Heck, do I have an article about it? Maybe I should write three just to make sure Google finds it :) :)
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Yacine

Yep, search the forum for "if strsame", you'll get 30 topics, of which most relate to this exact problem.
The issue is, that you can't expect visio to behave differently than (every?) other Software.
May be a "most common errors" article would be a good place for a hint?
Yacine

karininwinnipeg

 :D

Thanks, Chr, er, VisoGuy. I did find a post by you about this but I didn't really "get" it -- it was a bit more complicated than the great example you shared in this post.

Have a great day!

Karin

Visio Guy

The thought process is:

1. Convert a user-friendly search into a number
2. Convert that number into some other ShapeSheet quantity.

So:

1. "Red;Blue;Green"
2. User chooses Blue
3. Index is 1 (0-based)
4. Go get RGB(0,0,255) somehow

In ShapeSheet parlance:

Prop.Colors.Format = "Red;Blue;Green"
Prop.Colors = INDEX(0,Prop.Colors) //...set by Visio when user chooses from dropdown list

User.Index_Color = LOOKUP(Prop.Colors,Prop.Colors.Format)
User.Colors = "RGB(255,0,0)|RGB(0,0,255)|RGB(0,255,0)"  //...red, blue, green. Note the pipe | separator
User.Color = INDEX(User.Index_Color, User.Colors, "|") //...uses third argument to specify the separator

This example will have problems in Europe because they use ; as a list separator for function arguments.

My article http://www.visguy.com/2009/10/21/choose-colors-with-shape-data-fields/ might discuss this in the comments. I can't remember if I updated the article or not, and I don't have time to go over it right now.

For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010