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

Now, let me get this straight: Field naming conventions in the coconut

nurispark
Registered: Jul 30 2008
Posts: 6

[b]Really, I'm just asking for confirmation and/or to be corrected:[/b]
Say I've a form that a user created. It's 10 columns, 30 rows.
I created the first row's fields (some text, some combo boxes) with simple names (A, B, C, etc.) I then selected all the fields and used the Create Multiple Fields command to replicate these fields down the 30 rows.

[b]Here's the part where I get annoyed and where I think someone can tell me if I can't have my cake and eat it too:[/b]
Because I've created hierarchical fields (A encompasses A.0, A.1, A.2, etc.) I can use the preset calculation feature in a "total1" field that I've created elsewhere on the same page to simply calculate all fields A (again, A.0, A.1, A.2, etc.)
Remembering that this was all created [i]by[/i] Acrobat, my problem lies when I want to perform calculations [i]across[/i] columns and use the Simplified Field Notation (SFN) to calculate a row (A.0, B.0, C.0, etc.) by entering:
A.0+B.0+C.0
in the SFN JavaScript Editor and the calculation field remains empty -- signifying to me that there's an error. Later on, I will intend to use more-complex calculations, e.g.:
(A.0*5)+(B.0*20)
which I realize works fine if my fields weren't named with a period in the field-names, e.g.:
(A0*5)+(B0*20)
Am I wrong to want such things or am I just creating buggy code? I thought I was being so-very-careful with my programming too!

[b]To restate: Are all these below statements true?[/b]
1. Using hierarchical field names (i.e., names which start with a letter but contain a period followed by a number) is acceptable for calculations if I were to use ONLY the presets (sum, product, average, minimum, maximum) and selecting field names' check boxes.
2. Using hierarchical field names will [b]not[/b] work when attempting to use SFN.
3. I'm probably much better off just renaming all my fields and renaming them without a period and just use SFN (I'd prefer not to use JavaScript if I don't have to.) But this also means a more time-consuming time for me and those like me.

If there's a more elegant / better solution that won't make my brain fall out, I'm open to suggestion(s)! [i]Doctor, is there nothing I can take? I say, doctor, to relieve this calculation ache![/i]

My Product Information:
Acrobat Pro 8.1.2, Macintosh
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There is a reason it's called "Simplified Field Notation". There is an underlying process that converts the SFN into JavaScript. It only works for single word names.

Since you want to do calcualtions on both colums and rows you are no longer doing simple work. And you've got a lot of rows and columns. What are you going to do if you have to make changes later on? This could be very time consuming.

The solution is to use JavaScript. With proper naming(exactly what you are already doing) and JavaScript you can create generic fucnctions (i.e. independant of a specific row or column) to do your calculations. This is much more elegant than the brute force approach of putting individual calcualtions on each row and column, and much easier to maintain.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

nurispark
Registered: Jul 30 2008
Posts: 6
I reluctantly agree.
Last night, I broke down and used the Field tab to quickly run through ([F2], [arrow], [arrow], [delete] -- rather quickly) all the field names which had hierarchies that I needed to raize and renamed them without a period (A.01 became A01), and added zeros to the single-digits (1 became 01, etc.) I was then able to construct SFN formulas for my cross-calculated totals and keep the hierarchical fields which didn't -- plus, Excel did most of the work constructing the field names... [color=#FF0000]oh, series AutoFill, I heart you[/color]!

While I'm not afraid of JavaScript and have composed web pages utilizing it, the Adobe help application is fairly sparse. I feel like I don't even really know good search terms to learn more about the math involved -- keeping in mind I have a dual-degree in graphic design and languages ... [b]math = scary[/b].

In lieu of me doing more searches in the future, are there any [i]specific[/i] articles/tutorials that you believe I'd find [i]particularly[/i] helpful? (I have to admit, I do like [i]free[/i]...) :)

Thanks for confirming my suspicions. I'm going to look at the link posted in your signature as well! I suppose for now, aside from any specific pages you or anyone else suggests I read, I consider this post closed.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I haven't written anything on performing row and column calculations, but this is something that comes up pretty often. What you need to do is name the fields in the Array in a regular fashion so that you can easily generate all the field names by only knowing which row or column your calculation is on.

Just as an example: suppose you have a 3X3 array of fields. All are "cost" fields. Row 1 is "Cost1_1", "Cost1_2", "Cost1_3". Row2 and Row3 repeat the pattern. Then You have field to sum the rows and columns. The sum field for Row1 is "Sum_Row1" and the sum field for column1 is "Sum_Col1".

The calculation for Row1 looks like this

var sum=0;
for(var i=0;i<3;i++)
{
var cFldName = "Row1_" + i;
sum += this.getField(cFldName).value;
}
event.value = sum;

The calculation for Column1 looks like this

var sum=0;
for(var i=0;i<3;i++)
{
var cFldName = "Row" + i + "_1";
sum += this.getField(cFldName).value;
}
event.value = sum;

In this case the the only difference is in how the names are built for the calculations, and is a very simple difference because the fields are named in a way that makes them easy to re-create on the fly.


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

nurispark
Registered: Jul 30 2008
Posts: 6
Terrific examples. I'm gonna try them out this week in practice!

Thanks for the suggestion.