Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

Arithmetic over/underflow error on form open

jparris67
Level 1
Level 1

I've tried finding a solution to this on my own using other examples from previous forum posts, but nothing has worked. I have a form containing some fields that perform a simple "present value" calculation. The calculation works, but when you open the form, I receive the following error:

overunderflow.JPG

Of course, all of the fields involved in the calculation are blank when the form opens, so there's nothing to calculate, which is, I think, what is causing this error.

Is there some formcalc script I can use to prevent this error?

Thanks for any help you can offer!
Jamie

5 Replies
jparris67
Level 1
Level 1

Update: I did get the form to not show the error upon opening the form, but it still shows the same error when tabbing out of the InterestRate field (after entering a value) - and only this field.

(I had originally had "0" as the default value for all fields, but once I removed that, the error now only appears when tabbing out this field.)

I'm not really savvy with formcalc yet, so I'd love any help you can offer. Thanks so much!

SI_MSD7
Level 6
Level 6

Typically this means there's something in your calculation that causing the overflow and may happen until you (or the user) enter data that doesn't cause an overflow. Is the calc dependent on two or more separate values that must be present in order to get a valid result?

Depending on what the calculation takes place (i.e. on Exit event) you might be able to modify the script to something like:

if ( $ > 0) //only perform calc if entered value is gretare than zero

then

perform calc script  //place your script here

else

$ = "" //keep blank

endif

jparris67
Level 1
Level 1

The calculation for the PresentValue field is PV (PaymentAmount.rawValue, InterestRate.rawValue / PaymentsPerPeriod.rawValue, TotalPayments.rawValue). All of these fields have to have a value (user-entered) to calculate the PresentValue field. The calculation works just fine, it's just that when you place a value in InterestRate, before placing a value in PaymentsPerPeriod (by which InterestRate is divided), you get the error. So, I need to be able to tell it to only calculate when InterestRate is not zero, but I can't find the right script to make it work.

SI_MSD7
Level 6
Level 6

That makes perfect sense. It form is alerting you of the error since you can't divide by 0 (or whatever the issue is...mathematically.)

If you are using FormCalc vs Javascript, try the following in the PresentValue field...NOTE: You may need to adjust depending on the path of your fields (i.e. if they are wrapped in subforms).

if (InterestRate > 0)

then

$ = (PaymentAmount * InterestRate) / (PaymentsPerPeriod * TotalPayments)

else

$ = ""

end if

(YOU CAN use InterestRate != 0 instead of  "> 0" if desired)

//Javscript method

If you are using javascript then the code would be modified as such (NOTE: .rawValue isnt used for FormCalc):

if (InterestRate.rawValue > 0){

this.rawValue = (PaymentAmount.rawValue * InterestRate.rawValue ) / (PaymentsPerPeriod.rawValue  * TotalPayments.rawValue );

else{

this.rawValue  = "";

}

jparris67
Level 1
Level 1

Thanks for your response. Unfortunately, it didn't work, and it produced an inaccurate result.

Here's what I did:

PV (PaymentAmount, InterestRate / PaymentsPerPeriod, TotalPayments)

if (InterestRate > 0)

then

$ = (PaymentAmount * InterestRate) / (PaymentsPerPeriod * TotalPayments)

else

$ = ""

endif

The formula is wrong, so it produced the wrong result, and the error appeared for every field except PaymentAmount. Weird.

So, I tried this:

PV (PaymentAmount, InterestRate / PaymentsPerPeriod, TotalPayments)

if (InterestRate > 0)

then

$ = (PV (PaymentAmount, InterestRate / PaymentsPerPeriod, TotalPayments))

else

$ = ""

endif

This produced the right result, but I still received the error message when tabbing out of InterestRate.

As a workaround, I can swap the fields so that PaymentsPerPeriod appears first, which would work fine unless someone manually filled in the InterestRate field first without using the tab function. I just wish I could get a script to work.