Zum Hauptinhalt gehen

Suche

Suche

How To Add Up Text Fields And Show The Result In A Text Field

Kommentare

3 Kommentare

  • Avatar
    Permanently deleted user

    First, you will need to give each one of the fields you wish to sum up a name, using the "Named Data Source" feature.  On the Data Source tab, give it a name.

     

    Then, in the text field that is going to sum the others, change its type to VB Script, "Single Line Expression".  Then give it an expression like this:

     

    CDbl(Format.NamedSubStrings("A").Value) + CDbl(Format.NamedSubStrings("B").Value) + CDbl(Format.NamedSubStrings("C").Value)

     

    This sums up three named data sources, treating them like floating point values.  The CDbl is a conversion function that tells VB Script to treat the text as though it is a floating point number (e.g. "9.4") otherwise it won't really add the values numerically like you'd expect.

     

    If you already tried this and it didn't work, one reason might be that the source data already has the % sign in it, and VB Script doesn't recognize that.  So you'd probably need to break the % sign into a separate data source, so that the named data sources do not include the % sign.

     

    If this is not enough information to help, you will need to provide some more information about your format and the data it contains.

    0
  • Avatar
    Legacy Poster

    That definitely helps me out. I didn't know about the CDbl command.

     

    Appreciate the help

    Travis

    0
  • Avatar
    Legacy Poster

    Okay, got it working too! Here is the full line of code I used, just in case anyone else is having the same issue.

     

    Value = CDbl(Format.NamedSubStrings("A").Value) + CDbl(Format.NamedSubStrings("B").Value)
    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.