Custom formulas in fields

Started by Jennifer, April 13, 2014, 01:47:58 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jennifer

I would like to get a rectangle to display both of its dimensions (height & width). It's easy enough to get it to display one or the other by inserting a field and using one of the Fields in the Geometry category.

Just as a test, I selected the Custom Formula category entered this formula:
=Width&" x "&Height

This actually works, but it doesn't seem to respect the Format settings. No matter what format I select, it always shows the full precision and hte units.

Is there a way to get this to use the Format settings, such as "0.0"?
Using Visio 2019, part of Office 365 on Windows 10

wapperdude

You can use the format function.

Replace your width with FORMAT(Width,"#.# U").  The number of #'s after the decimal determine the amount of precision.  The upper case "U" makes the units capitalized.  Use a "u" if you don't want caps.  Then do same thing for height.

HTH
Wapperdude.
Visio 2019 Pro

wapperdude

#2
You can try the following as a custom formula:  =FORMAT(Width,Fields.Format)&" x "&FORMAT(Height,Fields.Format)

This ought to automate both the precision and units.  It seems to work for most cases.  So, enter the custom formula in the insert > fields dialog box.  Then, click the data format and select precision and units.

HTH
Wapperdude
Visio 2019 Pro

Jennifer

Quote from: wapperdude on April 13, 2014, 02:43:04 AM
You can use the format function.

Replace your width with FORMAT(Width,"#.# U").  The number of #'s after the decimal determine the amount of precision.  The upper case "U" makes the units capitalized.  Use a "u" if you don't want caps.  Then do same thing for height.
That works perfectly. Thanks. I think I should have thought of that. :-[
Using Visio 2019, part of Office 365 on Windows 10

Jennifer

Quote from: wapperdude on April 13, 2014, 04:28:31 AM
You can try the following as a custom formula:  =FORMAT(Width,Fields.Format)&" x "&FORMAT(Height,Fields.Format)

This ought to automate both the precision and units.  It seems to work for most cases.  So, enter the custom formula in the insert > fields dialog box.  Then, click the data format and select precision and units.
That one works most of the time. Sometimes it gets an error message, something about invalid syntax or something.

But how come the formula "=width" respects the precision setting, but "=width&" x "height" doesn't? Seems like a bug.

Anyway, thanks for the help.
Using Visio 2019, part of Office 365 on Windows 10

wapperdude

Possibly a bug.  I suspect that there was no vision of having multiple field entries, so the underlying code doesn't anticipate that.  My work-around is, at best, leveraging the bug, or loop-hole in the code.  It's not a robust fix.  I suspect a reliable solution would involve some code.

There might be another clunky, but, perhaps reliable solution...
Use two text boxes:  1 for width and 1 for height.  That way, each gets a single field entry.

Wapperdude
Visio 2019 Pro