Dynamic calculate



Hi Folks
I’m really love the Axure but I have one problem with my project.

I want to create calculator with two inputs: amount and period. The sum should be dynamic recalculate (amount over the period) during tap + or - and dispalyed in the separate place. Beside this, after controller switch on should be added example digit: 6 to the total sum. And the other status Switch off decucts digit from the sum.

Calculate.rp (61.6 KB)


Here is a solution based on my understanding of your problem.

See Page 2 of this updated file:
Calculate.rp (87.7 KB)

It sounds like your calculation divides the Amount by the Period and shows it in Result. This should happen automatically when the user clicks any + or - button. I would expect that entering values directly (by typing in either text field) would also update the result, and furthermore that division by zero (or blank) should not be possible, so I included that safeguard as well.

Adding 6 to the result when the toggle switch is on makes sense, but should -6 be added any time the switch is off, or only after it has been turned off? As an example, let’s say a user sets Amount to 1000 and Period to 2, but never touches the toggle switch. Should the Result value be 500 or 494? I assumed it should be 500. Then, if user turns the switch on, Result would be 506, and if user turns the switch off, Result would again be 500. If this is not the case, the logic is easy to change.

To perform the automatic calculation, I used the Text Field widget’s Text Changed event. Because changing either the Amount or Period fields would change the result, I could have put the same logic on both widgets. However, that would mean any time you needed to edit the calculation you would need to edit both, which is inefficient and prone to mistakes. So instead, I only included the calculation logic once, on the Amount text field (named, “textfield1”). When the Period text field (named, “textfield2”) changes, it triggers “textfield1” to perform the calculation. To accomplish this, “textfield2” has a Text Changed event with one action:

Fire Event
textfield1 fire Text Changed

…In this way, it forces the interaction logic on the “textfield1” widget to be performed even though that widget’s text did not actually change.

The basic formula I used for the calculation is this expression:
[[ (This.text / LVAR1).toFixed(2) ]]
…where This.text refers to the text on this widget
LVAR1 is a local variable pointing to the text on textfield1
.toFixed(2) forces the result to be shown with two-digit precision

You can inspect the Text Changed event on textfield1 to see how it looks at the state of the Switch dynamic panel to determine if it is on, and if so add 6 to the result, else it just calculates the result, else (if the Period is less than or equal to zero) it just sets the result to equal the Amount (as if the Period were set to 1.)

When the user clicks on the toggle switch, I use Click or Tap to change the state, with wrapping, just as you had it. However, I also use the Panel State Changed event to adjust the value of the Result (“textfield3” widget). This is a more reliable way to handle the effects of the toggle changing from on-to-off and off-to-on.


Thanks a lot! I’ve solved my problem from the other side. Beside this, I have an another question. Do you know match formula which block amount counter on “0”? In my counter “MinusButton” causes values below zero.


In general, you can enforce limits in your conditional case logic. Something like on a button, a case like,

If TestValue is greater than 0
Set TestValue equal to [[TestValue - 1]]
Else if true
Set TestValue equal to 0

As I recall, I included this in the sample .rp file here …look at the Minus buttons in my examples.