Using the new Calculation control

The Calculation control lets you display the result of a calculation without doing any coding. As the input values of the formula are changed, the value displayed in the control is automatically updated.

Screen Shot 2015-01-16 at 11.15.43 AM

It’s much like a Label, in that it displays a simple text string. It has many of the same properties: font, alignment, etc. However, instead of a caption, it has a formula. Each time you enter a character on the screen, formula is reevaluated and the new result displayed.

Let’s have fun with some formulas:

(Number(TextBox1.value) - 32) * 5/9

This is a simple formula to convert Fahrenheit to Celsius. We get our input value from TextBox1. Since it is stored as a string, we use the Number() function to convert it to a number, and plug it into the formula. If you change the value in Fahrenheit into TextBox1 and the new Celsius temperature will be displayed right away.

Number(TextBox1.value) * Number(TextBox2.value)

The image above uses this formula. We need to get the values of TextBox1 and TextBox2. The formula multiplies them and the result is displayed.

txtFirstName + " " + txtLastName

The expressions you put can into formula are not limited to numbers. In this case, we are displaying a string expression: concatenating first and last name, with a space in between.


Elsewhere in your program:

Function factorial(n)
  if (n <= 1) return 1; 
  return n*factorial(n-1); 
End Function

Now we're having almost too much fun. We're using our own function in our formula. The factorial function is called each time the value in TextBox1 changes and the value is updated.

Since the formula is called on every keystroke, there are all sorts of other things you could do to update the screen.

One note: the formula needs to be valid JavaScript, not BASIC. In many cases, they are identical. If you have an expression in BASIC that you wish to translate into JavaScript, enter it into the Code Window and highlight. Right click and choose 'View JavaScript'. You can then copy that into formula.