/ Id-Extras Forum / subtraction of two fields

  • Author
  • #6187 Reply

    I’m trying to subtract two fields. I have no idea how to do it
    I’ve attached what i’m working on

    #6382 Reply
    Ariel
    Keymaster

    Hi Jennifer,

    Even Acrobat itself doesn’t offer a simple way to do subtractions. Not quite sure why, but probably because x – y (and x / y) is not the same as y – x and y / x (as opposed to addition and multiplication, which are commutable).

    So a custom calculation script is needed to handle this.

    The basic idea is as I mention in this thread: http://id-extras.com/forum/viewtopic.php?id=53

    In your case, we would need to modify it a little, like this:

    To get the value of a field, use this command:

    Code:
    this.getField(“Field1”).value

    To update the value of the selected field, use:

    Code:
    event.value = …

    So putting it all together, try the following as your custom calculation script:

    Code:
    event.value = this.getField(“Field1”).value – this.getField(“Field2”).value

    Does that work?
    Ariel

    #6383 Reply

    no. I have to be doing something wrong.

    by selecting the field for “Profit $” (see my screenshot)
    i put in a custom script under calculate>custom calculation script:
    event.value = this.getField(“Field45”).value – this.getField(“Field50”).value

    brought it into adobe and used Edit>FormMaker and it did not fill the field correctly

    #6384 Reply
    Ariel
    Keymaster

    Can you post the PDF here (or send it to me privately) AFTER running FormMaker on it in Acrobat?

    #6385 Reply

    here you go

    #6386 Reply
    Ariel
    Keymaster

    By the way, looking at your screenshot, I hope you are aware of the “calculation order” issue. In your form, it is important that some fields are calculated first, and other fields later, and the final field last of all. Being aware of this in advance will save hassle later on.
    With FormMaker, a number at the end of the name of a form field (which is set in InDesign’s Buttons and Forms panel) decides the calculation order for the field. The higher the number, the later the field is calculated.
    For instance, if one field is called “Text Field 3” and another is called “Text Field 10”, and both have calculation scripts attached to them, the calculation script attached to Text Field 3 will be run before that of Text Field 10.
    More details here: https://www.id-extras.com/help/formmaker-help/

    #6387 Reply
    Ariel
    Keymaster

    Thanks for posting the form.
    Ok, so it’s a simple mistake, easy to make.
    Your script is:

    Code:
    event.value = this.getField(“Field45”).value – this.getField(“Field75”).value

    But the names of the fields in question are actually “Text Field 45” and “Text Field 75”, respectively. So the script should look like this:

    Code:
    event.value = this.getField(“Text Field 45”).value – this.getField(“Text Field 75”).value
    #6388 Reply

    AWESOME SAUCE!

Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: subtraction of two fields
Your information: