These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Calculation Delay

Duniagdra
Registered: Sep 24 2008
Posts: 140
Answered

I don't know. I have multiple fields calculating based on the results of other fields and in order to get them to calculate I have to enter a value in other fields to force them to calculate.

My first field, "Strength" requires a user input.
My next field, "Ability_Mod_STR", displays a result based on value in "Strength".
My third field, "Ability_STR_ModLevel", displays the total of result from "Ability_Mod_STR" plus another field.
Then another field, "Fort_Ability" compares the values of "Ability_STR_ModLevel" and "Ability_CON_ModLevel" and displays the higher value or one if equal.

In order for these fields to do their thing, I have to manually enter values in other fields on the form, then they calculate. Here is the code I hacked from scripts I found here and elsewhere.

FIELD: Ability_STR_ModLevel

var Mod = Number(this.getField("Ability_Mod_STR").value);
var Level = Number(this.getField("Init_Level").value);
var Score = Mod+Level;
event.value  = Score;

FIELD: Fort_Ability
var STR = Number(this.getField("Ability_STR_ModLevel").value);
var CON = Number(this.getField("Ability_CON_ModLevel").value);
 
if( STR > CON)
{
    event.value = STR;  
}
else if(STR == CON)
{
   event.value = STR;
}

Is it something I did wrong or a setting I'm missing for calculations.

Thanks in advance,
Jim

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

My Product Information:
Acrobat Pro 8.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
A field's Calculate event gets triggered whenever any other field value changes, in the order defined by the field calculation order.

It's not clear to me what problem you're having. Perhaps the field calculation order is wrong. If it's not behaving how you expect, please explain exactly how you expect it to behave.

That last bit of code does not seem complete. Did you leave something off? If not, can you clarify what you want the value to be if CON is greater than STR?

George
Duniagdra
Registered: Sep 24 2008
Posts: 140
George_Johnson wrote:
A field's Calculate event gets triggered whenever any other field value changes, in the order defined by the field calculation order.It's not clear to me what problem you're having. Perhaps the field calculation order is wrong. If it's not behaving how you expect, please explain exactly how you expect it to behave.
Okay, maybe I need to address that then. I'll check it out.

George_Johnson wrote:
That last bit of code does not seem complete. Did you leave something off? If not, can you clarify what you want the value to be if CON is greater than STR?George
Perhaps this could be another part of my problem. If the code gets confused... In the above code, Ability_STR_ModLevel reacts off the result of Ability_Mod_STR, which runs a script you helped me with in a recent post. Then Fort_Ability compares the values for STR and CON and should take the higher or either if equal (I'll say STR).

Um... does it make any difference that the variable in each field is identical?

Example:
Ability_STR_ModLevel
var Mod = Number(this.getField("Ability_Mod_STR").value);var Level = Number(this.getField("Init_Level").value);var Score = Mod+Level;event.value  = Score;

Ability_CON_ModLevel
var Mod = Number(this.getField("Ability_Mod_CON").value);var Level = Number(this.getField("Init_Level").value);var Score = Mod+Level;event.value  = Score;

Etc., etc. four more times. Can this cause an issue? I think the variables become specific to each field, no?

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Duniagdra wrote:
Can this cause an issue? I think the variables become specific to each field, no?
You would think so, but it actually sets up variables that are global to the document. Even though you would think the variables get reset each time the code is executed, I've encountered cases where it is not, so I always either place my field-level code that declares variables inside of an anonymous function that calls itself or place it as a document-level function that gets called in the field event.

For an example of the first approach:

(function () { var Mod = Number(this.getField("Ability_Mod_CON").value);var Level = Number(this.getField("Init_Level").value);var Score = Mod+Level;event.value  = Score; })();

This way all of the variables are local to the function and there are no issues with interference from other field events.

I don't have time now to review all of what you just posted, but try this suggestion and post back. If you do this, be sure to clode the file and reopen it before testing.

George
Duniagdra
Registered: Sep 24 2008
Posts: 140
Sorry for taking so long in responding George, but I had time now to play with this idea and I do have to say
[img]http://www.godieselracing.com/forum/images/smilies/bow28.gif[/img]
I bow to you.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack