Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate a total from an unknown amout of field values

Status
Not open for further replies.

cstaines

Technical User
Nov 6, 2003
3
AT
I am trying to calculate the grand total of field values that have been populated by users.

I do not know in advance how many fields will be filled out

I have tried to do simple addition
FIELD1+FIELD2+........ but if the user only populates FIELD1 then it does nothing.

I have tried also the following formula
mtotal := @If(field1 = ""; 0; field1) + @If(field2 = ""; 0; field2) +...;

But it dosen't work

Can anyone help ?????
 
When/where/how are you doing the calculation? In a button action? A document event?

Also, what are the default values of your Field1, Field2, etc? If the default values are zero, then you should be able to do the addition fairly simply, I would think. If the default value is "", I would look into changing it to zero.

If there is no default value, then your check for field1 = "" might not be working since the filed mioght be Null and not "". (someone correct me here if I'm confused, please.)

And in your formula, you might need to add the trim function, like this:

mtotal := @If(@Trim(field1) = ""; 0; field1) + @If(@Trim(field2) = ""; 0; field2) +...;

Post your field attributes and your actual code.

peace.
 
Hi peace!

thanks for the reply.

I am using the following fields (and Attributes)

Field "GesKost1" is a number field with the following code "@Text(Stunden1*Kost1)" this code calculates the.

Field "ShowKost1" is a number field also that has the following code "temp := @TextToNumber(GesKost1);
@If(@IsError(temp);"0";@TextToNumber(GesKost1))"

There are a total of 15 fields for GesKost (GesKost1, GesKost2 .......... GesKost15) & ShowKost (ShowKost1, ShowKost2......ShowKost15)

I do not know id advance how many fields the user will populate.

The calculation is performed using the field "Summe" a number field whose formular is is "ShowKost1+ShowKost2+ShowKost3........ShowKost15"
This is translated again using a field called "ShowSumme" a number field whose code is"@Text(@Sum(SummePW))"

This code works but only when all of the fields are populated in the formular. If the user only populates two fields then nothing happens.

 
No prob, cstaines.

A couple of questions pop to mind after briefly reading your last post:
1. Where exactly is the @Text(Stunden1*Kost1) code for the field GesKost1? In the default value? As the input
translation formula?

2. Why are you @Text-ing if GesKost1 is already a number field?

Keep it comin'......
;-)
 
Hi Peace !

Your questions made me think again.

I have reviewed all of the data inputs and field defaults again.

I was @-Texing because I was getting some values from an @DbLookup.

I have reviewed and slightly changed the code again and guess what......

It WORKS !!!!!!!


Thanks again for your help

PS. do you know of any good Databases that show examples of coding ?

I am using R5. I have been learning by doing so far (as you can probably tell !)

take it easy.........

Chris

 
Chris - Coding in Notes is strangely satisfying in that simple things often are the hardest to figure out! Ha!

Glad you got it working!

Trey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top