How To Add Up Text Fields And Show The Result In A Text Field フォローする

0
Avatar
Legacy Poster

I use Bartender mainly for creating analysis tags for agricultural stock. On the tag each field shows a component by percentage, which adds up to 100%. I have some new employees coming in and would like to have a text field off to the side that adds up each one, so they can easily see if they have made a mistake. I've messed with it a little bit and I can program, but the most I've been able to do is to get the text field to match a single text field. I've tried changing data types and all that, but at this point I'm a bit lost, and before I go and bother our Bartender sales rep, I was wondering if anyone here new a solution.

 

Thanks,

Travis

3 コメント

0
Avatar
Ian Einman
コメントアクション Permalink

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
コメントアクション Permalink

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

 

Appreciate the help

Travis

0
Avatar
Legacy Poster
コメントアクション Permalink

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)

ログインしてコメントを残してください。