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

How to script/calculate either or fields

Formfingers
Registered: Feb 7 2007
Posts: 90

I've looked in the script guides and throughout the forums without luck on how to exactly get this script of mine to work.

I have two tables: the first with three fields...A, B, C.
My second table has various rows and columns that will automatically calculate into a "total" column based on what the user enters into A, B, or C.

MY PROBLEM: How do I script "or", "either", "if/else", or whatever wording that essentially allows my table to calculate the amount depending on what field the user types into. For example:

Total = Table1.Row1.A * Table2.Row2.Miles
or
Total = Table1.Row2.B * Table2.Row2.Miles
or
Total = Table1.Row3.C * Table2.Row2.Miles

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
First you need to establish the rules for which each calculation will be run and then figure out how to write the logical test to arrive at a true value.

You can then use those logical statements in the "if" statement (form the "Scripting Reference" under LCD "Help") for FormCalc:

Syntax:

if ( simple expression ) then
list of expressions
elseif ( simple expression ) then
list of expressions
else
list of expressions
endif


The result of the list of expressions associated with any valid conditions
stated in the if expression.

Note: You are not required to have any elseif(...) or else statements as part
of your if expression, but you must state the end of the expression with endif.

George Kaiser

Formfingers
Registered: Feb 7 2007
Posts: 90
Thank you gkaiseril -

Being that I'm not a programmer, I cannot get your sample if/else statement to work correctly; there's something I'm missing and not wording right. Believe me, I'm trying! =) I'm at a loss as to why I can't stipulate that whatever field within my row is entered, it autofills my total box.

My script currently reads:
Table2.Total = Subform1.Table1.Row[*] * Table2.Price

Basically, I've got 5 boxes in my "Table 1 Row" and a user may fill out one, two, some or none - whatever they enter, it needs to calculate with my "Price" field (value set to .297) and then the Total generates. For me to come up with an "if/else" statement against all the possibilities...well, obviously I'm WAY lost.

How is there no simple way to say, "If a user enters here, here, or here, it multiplies that number times this field and then here's your total." I placed [*] in my script, thinking this would account for any field within that row that was entered....but it's not working.

Any other ideas?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
What was given is the "syntax" or diagram of the statment, sort of like a sentance digram with the part of speech. You need to replace things like "simple expression" with a logical JavaScirpt or FormCalc statment like "HasValue(Table1.Row1.A)" which will be "true" if there has been any valid entry in the field "Table1.Row1.A". So for the "Total" field's calculation script in FormCalc one could have:

if ( HasValue(Table1.Row1.A) ) then
Table1.Row1.A * Table2.Row2.Miles
elseif ( HasValue(Table1.Row2.B ) then
Table1.Row2.B * Table2.Row2.Miles
esleif ( HasValue(Table1.Row3.C) ) then
Table1.Row3.C * Table2.Row2.Miles
endif

But this assumes that an entry in "Table1.Row1.A" prevents any entry in the onther fields.

If you are going to continue to try to write scripts, you need to review the eSeminars on demend, look at the "Scripting Reference" under LiveCycle Designer's "Help" menu option and look at the sampel templates within LiveCycle Designer.

George Kaiser

jkase
Registered: Nov 8 2008
Posts: 4
I am just a beginner and I am having trouble already.
In the Library palette under custom there is a Country field box icon and US States Icon,
How would I get the Country box to change the state box when picking another country?
For example: if I were to pick the country United States the US states appear in the drop down for states and if I were to pick Mexico I would like the 31 states of Mexico appear in the drop down for states.
I hope there is a way to do this or if someone can direct me to where I might find an exisiting form I could look at it and get an idea of what to do. it seems that there might be one out there somewhere.
Thanks in advance,