I’ve created a fancy calculator shape that evaluates mathematical expressions, and allows you to save the results, like the ticker-tape on an adding machine!

Happy New Year, everybody! Let’s get 2019 rolling with something not-too-serious: a crazy calculator shape! (And be sure to get the Visio Year Calendar for 2019 before 2019 gets too far along!)

Often when I’m working on a drawing in Visio, I need to perform some calculations. This usually happens when I’m laying out a 2D space plan, or designing some simple thing that I’m going to build out of cardboard over the weekend.

It’s easy enough to anchor Window’s calculator to the Task Bar and have it ready at a moment’s notice, but having another window open is awkward. And for quick calculations, Excel can be overkill. Plus with Excel, you might need to save the file, which then becomes “just one more darned thing to deal with”. (Does Excel have a feature to auto-save unsaved/unnamed files like Notepad++ does? And if not, *why *not?)

Also, Calculator and Excel don’t understand *units of measure*, so they’re merely “number slingers”. Try this with Excel or Calculator:

As an American living in Europe, I truly appreciate being able to quickly convert between Freedom Units and the Metric System.

Anyway, with a small amount of Visio ShapeSheet know-how, those two rectangles become a powerful calculator! I usually end up looking for one of my existing calculator shapes, or I punt and just build a new one on the spot. I’ve written about the basic technique in Evaluate Shape Text With EvalText. It’s pretty easy.

Calculator shapes in Visio are quite simple. They require only two rectangles: one for typing expressions, and another for displaying calculated results. You can group them together in one nice, neat package. You can quickly Ctrl + Drag copies of the calculator if you need to preserve expression + result pairs for future reference. They support units like inches, feet, millimeters, centimeters, etc., as well as mathematical expressions and functions. And they’re in Visio, right there on the drawing page, next to the stuff you’re working on. The ultimate in convenience and flexibility. The only difficulty is in learning a bit of Visio ShapeSheet syntax, and the conventions for referring to other shapes in formulaic expressions.

In the old article, I didn’t provide a downloadable shape (sorry!) because **A.** I outlined in detail how to build one yourself, and **B.** I figured you all needed the practice, ha ha!

But today I’m in a less-professorial mood, and wanted to create something nifty for you to *actually *download and hopefully put to good, time-saving use.

### Overly Complex Free Download

Fellow Microsoft MVP John Marshall (visit his site) has accused me of creating “Rube Goldberg Shapes” that are very complicated, and difficult to dissect and learn from. In order to live up to that reputation, offering a simple calculator shape for download just wouldn’t cut it.

So I came up with the idea of saving a history of calculations in a single shape–sort of like those old adding machines that churned out ticker-tapes of calculations along with a lot of noise.

The result of my efforts looks like this:

You type an expression in the top box with the blue text, and the calculated result shows up in the black box. No need to hit [Enter], the shape calculates as-you-type. If you want to save the result to the light-gray log, you can double-click or right-click the shape, depending on shape options.

Check it out in this GIF animation:

As you can see, it’s a pretty powerful, free-form, flexible calculator. The main downside is that you have to know Visio ShapeSheet functions by heart to evaluate complicated stuff. The basics like plus (+), minus (-), multiply (*), divide (/) work just fine, and they don’t require much learning curve!

### Valid Expressions

The expressions that you can enter must be valid Visio ShapeSheet expressions. This sounds ominous, but keep in mind that the ShapeSheet is modeled after Excel, and has many similar functions. You can see a complete listing of Visio ShapeSheet functions here: Visio ShapeSheet Function Reference. Be sure to check it out!

There are all sorts of functions, such as ABS, MIN, MAX, AND, OR, SIN, COS, TAN, ACOS, ASIN, ATAN, LN, LOG10, SUM, FLOOR, CEILING, and many, many more!

You can also include units of measure in your expressions. Visio supports the following units:

- Millimeters (mm)
- Centimeters (cm)
- Meters (m)
- Kilometers (km)
- Inches (in)
- Feet (ft)
- Feet-and-inches (X ft Y in)
- Yards (yd)
- Miles (mi)
- Points (pt)
- Picas (p)
- Ciceros (c)
- Didots (d)
- Weeks (ew)
- Days (ed)
- Hours (eh)
- Minutes (em)
- Seconds (es)

Note the last five entries are actually units of time. Their unit abbreviations start with an “e” for “elapsed”. So “seven elapsed days equals one elapsed week” or “7ed = 1ew”.

You can specify the resulting units for a calculation using the “casting” technique that I wrote about in the article: Casting Units in Visio’s ShapeSheet. Essentially, the left-most term in an expression will determine the units of the entire calculation. If no units are specified, lengths are in inches, and angles are in radians. In the images above, I was able to cast radians to degrees, and millimeters-plus-feet to inches.

In the download that accompanies this article, I used the casting/conversion feature to do “time math”. Here we can see that we added “0es” (0 elapsed seconds) to 1 minute, 1 hour, 1 day, and 1 week to instantly reveal the number of seconds in each of those durations:

### Options, Options, Options!

The shape has options galore, which you can access by right-clicking, or by using the Shape Data panel, or by accessing the action tag menu that appears on mouse-over (it’s beneath the blue (i) icon that appears…)

I won’t bore you with gory details for every single item, but the most important ones are those concerning the log. If you right-click, you can

- Add the current expression + result to the log
- Remove the last line from the log
- Clear the log

There is also an option to set what happens when you double-click the shape. You can have a double-click append the log with the last expression-equals-result text. Or you can set it to the more traditional double-click to enter text-editing mode. If you usually overwrite the entire expression, then you can just select the shape and type, no need to double-click. If you’re comfortable with hitting F2 to enter text-edit mode, then using double-click to append the log will work well for you.

The Shape Data panel has some options that require user input, so it contains settings not available via right-click. Most of these concern font-width and unit- and number formatting. You can also copy the log text by selecting the **Log Text (for copying)** field and pressing **Ctrl + C**.

### Telling Stories with the Log

I find the log history useful. You can store a step-by-step derivation to tell a story, or just save a bunch of related calculations in one handy block. Below, we see that PI() is 3.1416, which is technically in radians. If we add 0 deg onto the left side of that expression, we effectively cast PI radians to degrees, and get 180, as expected. Then we can divide by four, and even take the cosine of the whole shebang:

You can copy the log’s text by selecting the Shape Data field **Log Text (for copying)**. The Shape Data panel doesn’t display multi-line text very well, but if you simply click on the field, rest assured that all of the text will be selected. You can then quickly copy it with a Ctrl + C.

If you don’t give a hoot about the log, you can hide it entirely by right-clicking or via Shape Data. Look for the setting **Show Log**, and uncheck it or set it to **FALSE**.

### Special Characters

Visio has an autocorrect feature that helps you out by messing up everything you’ve typed. One example is to replace the minus sign (-) with a hyphen (–). This messes up the evaluation of text, because the hyphen does-not-equal the minus. I’ve added code to the SmartShape that replaces some of these common auto corrections, so you can subtract using a hyphen without issue. But there are likely other examples that I’ve missed.

One example might be pretty quotes vs. normal straight quotes, e.g.: “quote” “quote”. While quotes aren’t likely to be part of your mathematical expressions, they often cause problems when cutting and pasting code from web sites to coding environments.

If an auto correction is messing up your math, just hit **Ctrl + Z** immediately after the auto correction happens, and Visio will revert to the character you actually typed.

### Get the Calculator with Log Shape!

Download “Calculator with Log Shape”

s!Aj0wJuswNyXlhzI8tXlj4e-Ohwt8 – Downloaded 2959 times – 103.00 B
## Leave a Reply