# Simple Calculation How to do it ?

## Recommended Posts

Dear All,

Cf. my attached file.

I am trying to do something who seems quiet simple:

I have a field called Total.

I would like that when:

1/ Input a number in the field Add to Quantity it do the addition of this number into the Total Quantity field.

2/ Input a number in the field Remove of Quantity it subtract this number into the Total Quantity field.

How could i do this ?

Thanks a lot for your help !

Cheers

##### Share on other sites

I responded but deleted it. I'm unsure what you are trying to accomplish. If you have a Total calculation and you have two fields (one to add and one to subtract) then the Total calc would be simply:

Add to Quantity - Remove from Quantity

But I've the feeling I'm missing something else you are looking for. Can you give examples of exact how you expect the Total field to behave if you enter something in each of the fields - give us a sequence of 3-4 entries so we can see the pattern you wish to achieve. In other words, if you have a 3 in the Add field, do you want it to add to the Total but then if you change the Add number, it adjust (so the Add and Remove always equal Total) or do you want to use the Add and Remove like a calculator with the figures adjusting each time?

LaRetta :wink2:

Edited by Guest
Modified

##### Share on other sites

Hello,

But there is still a problem:

When i input a number inside the field add to quantity or remove of quantity it well do the calculation.

Only problem, when i try to delete the number i inputed in the field add to quantity systematically the number one appears in the field.

It should be great that after you input a number inside the add or remove field, the number inputed automatically disappear.

Do you know how i could fix this ?

Thanks a lot for ur help.

##### Share on other sites

Okay, I find your response a bit difficult to follow. Please repeat it using different words and, give me example of the keystrokes (adding and deleting a number) and how the total field should accumulate your results. Then we can adjust accordingly. :smile2:

##### Share on other sites

Hello,

What Is happening:

1/ I write the number 500 in the field add to quantity.

2/ I press enter.

3/ Quantity field display value 500.

4/ I now try to delete the number 500 from the field add to quantity. Then the number 1 appears in this field and is added to the total quantity field.

So It seems impossible to remove the value entered in add to quantity or remove to quantity, which means then every addition or subtraction is false.

I hope now it is more clear :

Thanks

##### Share on other sites

Can you post a quick simple file for us to view what you mean? Zip it and it can be attached at the bottom of your post where it says in blue 'Manage Files'.

I don't understand why a 1 would pop into the Add field when you delete the 500. Don't worry, we'll figure this out together!

LaRetta

##### Share on other sites

Hello,

Here it goes :

Thanks to remove the .jpg after the .fp7

Thanks a lot !

##### Share on other sites

you should compress your .fp7 files before you post them as transmission could corrupt them.

but i think this is what your after?

Edited by Guest
NEW VERSION

##### Share on other sites

i just updated the sample file - a bit cleaner no need for global variable.

##### Share on other sites

Dear LaRetta,

Thanks it works now. I did a mistake before.

West Ocean, your script looks great, but when i copy it in my database it doesnt seems to work.

Could you please tell me if there is any special setup with it ?

Thanks

##### Share on other sites

i think the problem is you are in FMP8 and that doesn't support variables?

Edited by Guest
going from memory - yes 8 does variables.

##### Share on other sites

Hello,

I am using the fmp 9 Advanced.

Shall i work with it ?

Thanks

##### Share on other sites

this is how it should work?

http://screencast.com/t/f5xh70D7LmJ

##### Share on other sites

Dear Ocean West,

When i use ur script, nothing happend.

I add data in plus or less field an nothing change.

What is going wrong ?

Could you please have a look to my database i posted it before.

Thanks a lot,

##### Share on other sites

no problem I cleaned it up further and this should work for you.

tao-samples-stock.fp7.zip

##### Share on other sites

Dear Ocean West.

Thanks ! Now it works perfectly.

Could you please tell me what was the problem ?

Thanks

##### Share on other sites

each field sets the variable \$qty to it self plus or minus the Quantity then zeros it self out

the variable is then set into the Quantity field because of the let statement - any referenced field used in the calculation will trigger the field to be updated.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

×
×
• Create New...