Calculation

From NSB App Studio
Jump to: navigation, search

Calculation.png

Description

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.

To add a Calculation control to your app, choose the Calculation icon in the Toolbar, then position it on the Design Screen. Use the Property Editor to set the properties you need.

The most important property is formula. It contains a expression which is used to calculate the value of the field. Terms can be numbers, functions and values of other controls. Keep in mind that if you use a value from a control, it will probably need to be converted from a string to a number using the Number function.

formula needs to be valid JavaScript. In most cases, BASIC syntax will be identical.

Properties

Standard properties are supported, plus:

formula The expression to evaluate. Design time.

Events

Standard events are supported.

Examples of value of Formula

Multiply the value of two fields

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

Convert Fahrenheit to Celsius

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

Concatenate Fields - it's not just for math!

txtFirstName + " " + txtLastName

You can even call a function!

factorial(Number(TextBox1.value))

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