Page 1 of 1

Auto Calculation (or Recalculation)

Posted: Fri Apr 02, 2010 10:34 pm
by arkstar
I have 2 cards. I can enter a number on the first card that is used as a factor in a number of different calculations on the second card. If I change the number on the first card, I want everything to recalculate on the second card without changing one of the numbers on the second card. Or put another way, I would like to the second card to recalculate everything whenever I go to it. Right now it only recalculates if I change on a number on the second card.

Any ideas?

Thanks!
Rob

Re: Auto Calculation (or Recalculation)

Posted: Sat Apr 03, 2010 8:14 am
by jmburnod
Rob,
If i have understand what do you need you can use

• preopencard in the script of cd 2
• the function CalculMe in the script of cd 2 of in the stack script

Code: Select all

on preopencard
   put fld "MyNumber" of cd 1  into nb1
   put fld "myFactor" of cd 1 into TheFactor
   put CalculMe(TheFactor,nb1) into fld "Myresult" of cd 2
end preopencard

function CalculMe pFactor,pNombre
   put pFactor * pNombre into rCalculMe
   return rCalculMe
end CalculMe
regards

Jean-Marc

Re: Auto Calculation (or Recalculation)

Posted: Mon Apr 05, 2010 5:39 pm
by dunbarx
I would do the recalculation when you are working in the first card. There are a number of messages that can be sent to the second card as soon as you are finished with the first. Best would be within the actual script of the first card. Whatever you do there, when you are done, gather the data from card 2, do your calculation, and update card 2.

Seems cleaner to me.If you need help getting data from other cards within a working script, write back.

Craig Newman

Re: Auto Calculation (or Recalculation)

Posted: Sat May 15, 2010 3:14 pm
by arkstar
Thanks for the responses.

Maybe I didn't explain myself, I would like everything to calculate when the card is loaded and also recalculate when you either enter a number or change a number on the card.
For example, right now, if you change the tax rate, you have to erase the charge for the item and reenter the same number for it to calculate......

Like I said, I would like the calculations to execute whenever you enter or change a number.

Thanks!

Rob

Re: Auto Calculation (or Recalculation)

Posted: Mon May 17, 2010 5:29 am
by dsquance
Perhaps enterinfield would work. Some action like pressing enter will be necessary, anyhow, and something like:
on enterinfield
<whatever calculation with the new number in the specified field of cd 2>
end enterinfield

returninfield is similar or tabkey or whatever action the user applies.

Dave

Re: Auto Calculation (or Recalculation)

Posted: Mon May 17, 2010 4:28 pm
by dunbarx
I made two fields, one named "entry" and one named "results". In the script of fld "entry" I put:

Code: Select all

on rawKeyUp
    if me is a number then put 1.05 * me into fld "results"
   pass rawKeyUp
end rawKeyUpy
Is this what you wanted? The "results" field contains the original value plus 5% tax. Your call. Note that there is little checking included to make sure the data is entered on only one line, or other possible entry oddities. I did check to see if the entry was a number.

Craig Newman

Re: Auto Calculation (or Recalculation)

Posted: Wed May 19, 2010 10:35 am
by arkstar
Thanks for the responses as I really appreciate it, but I don't think it does what I need.
I am passing a couple of number from one card to another.
When the second card loads, the numbers I've passed do apear, but none of the calculations takes place.
I have to change one of the numbers to make the calculation work.

Example:
Card one: I pass a charge per guest from this card to card two.
Card Two: Loads, shows the charge per guest from card one. On this card, I add sales tax, and service charges then show the final total.
In order for the final total to calculate, I have to edit or reneter the charge per guest I passed from card one, then it will calculate.

Is there any way to automate this so the user will not have to do anything?

Thanks again!!

Rob

Re: Auto Calculation (or Recalculation)

Posted: Wed May 19, 2010 12:16 pm
by bn
Rob,
how do you trigger the calculation on the second card? Is it in the script of a field?
Maybe you could post the calculation code on the second card. Than it is easier to find a way to trigger it from the first card.

If it is in the script of the fields on the second card you could separate the calculation from the trigger (I assume it is some sort of closefield/exitfield) by putting a script into the card script of card 2 that does the error checking and calculation. That way you could fill in the field charge per guest on the second card by script and than send "calculateTotal" to card 2.

Or you could just send the trigger to the field of card two.

Suppose you trigger the recalculation on the field "charge" on card 2 by a closeField handler than you add to the handler on card 1 field "charge" that puts the new number into the field charge on card 2 a

Code: Select all

send closefield to field "charge" of card 2
That should do it.

regards
Bernd