- chris cambré
If you are accustomed with conditional calculation and conditional showing you can create formula solvers. You just have to fill in all but one Input Boxes. The last remaining Input Box will be automatically be filled in with the calculated value. Following applet shows an exemple for a financial calculator on Simple Interest.
How do you do this?
- 4 numbers: Create the numbers
P = 1,
R = 1,
T = 1and
I = 1as starting values for the parameters.
- 4 calculated values: Calculate the value of each parameter out of the other 3 given values.
Pcalc = 100I / R / T-
Rcalc = 100I / P / T-
T calc = 100I / P / R-
Icalc = P R T / 100
- 4 empty texts: Create 4 Input Boxes we will use to create empty Input Boxes. emptyP = "", emptyR = "", emptyT = "", emptyI = ""
- 4 texts: Create 4 dynamic texts with the calculated values to fill in for the last missing value. - a text solP that shows calcP. Select calcP in the list of objects. - a text solR that shows calcR. Select calcR in the list of objects. - a text solT that shows calcT. Select calcT in the list of objects. - a text solI that shows calcI. Select calcI in the list of objects.
- counter: Create a number
filled = 0to calculate the number of filled in Input Boxes.
- 4 Input Boxes:
Create 4 Input Boxes linked to the 4 empty texts to create an empty Input Box.
Open the Properties of each Input Box and type the scripting commands to do three things:
- assign the filled in value to the according parameter,
- increase the counter of filled in Input Boxes with 1,
- and fill in the missing value if the counter eaquals 3.
Input Box 1:
Explication of the scripting commands: -
Caption Linked object Script P emptyP
SetValue(P,%0) SetValue(filled,filled+1) SetValue(emptyR,If(emptyR=="" && filled==3,solR,emptyR)) SetValue(emptyT,If(emptyT=="" && filled==3,solT,emptyT)) SetValue(emptyI,If(emptyI=="" && filled==3,solI,emptyI))
SetValue(P,%0)assigns the filled in value to the numer P. -
SetValue(filled,filled+1)increases the value of the numver filled with 1. -
SetValue(emptyR,If(emptyR=="" && filled==3,solR,emptyR))is the most tricky: If the Input Box for R is still empty but 3 Input Boxes have yet been filled in, then this is the 4th so it will be automatically filled in with the calculated value for R. The same we do for the Input Boxes for T and I. Other Input Boxes: The script of the other 3 boxes is written the same way to assign the filled in value, to increase the counter filled and eventually automatically fill in the 4th Input Box.