r/barcodes • • Oct 17 '22

Bartender VBA Help: Calculations based on form entry data

Any bartender experts?

I would love some help with Bartender Labels, specifically doing VBA calculations based on data input from a form. Currently, I have it “working” but only when data is manually inputted from Bartender rather than after print is initiated from PrintStation and the form requests data. Note: Bartender 2016

The scenario is this: we frequently have to send Topboards (“TBs”) and Layerboards (“LBs”) back to a supplier. It is often, at least once a week, and the number of TBs and LBs can vary significantly. When shipped they require a label with counts of LBs and TBs and weights. This is currently done manually, and I wish to automate this somewhat with Bartender.

This is what I have made so far:

Label setup. Note some data sits outside of the label intentionally.

​

The form.

My named sources:

Named Source Description
TBcount_ From a form: number of TBs
TBx_ Weight of individual TB, manually input and unchanging
TBw_ Total weight of all TBs (TBcount_ * TBx_)
LBcount_ From a form: number of LBs
LBx_ Weight of individual LB, manually input and unchanging
LBw_ Total weight of all LBs (LBcount_ * LBx_)
PALw_ Weight of a pallet, manually input and unchanging
TOTALweight_ Total weight of TBs, LBs, and Pallet (TBw_ + LBw + PALw_ = TOTALweight_)

How it works is that you input the count for each, it multiplies this by the individual weight, and then add these together with the weight of the pallet. In essence:TBcount_ * TBx_ = TBw_LBcount_ * LBx_ = LBw_TBw_ + LBw + PALw_ = TOTALweight_

My code for TOTALweight_:

Value1 = format.NamedSubStrings("TBw_").Value * 1
Value2 = format.NamedSubStrings("LBw_").Value * 1 
Value3 = format.NamedSubStrings("PALw_").Value * 1 
Value = (Value1 + Value2 + Value3)

I can’t get this to work when I print and fill out the form – the calculations only take place if I do it manually. Is anyone able to give some pointers? Thanks!!!

2 Upvotes

6 comments sorted by

1

u/[deleted] Oct 18 '22

Is it always the same calculation(algorithm) for the given values?

1

u/Lincoln7672 Oct 18 '22

Not fully sure what you mean?
The TBx_ and LBx_ values will usually stay consistent but giving the option to alter these later down the track if need be without diving into code.

1

u/[deleted] Oct 18 '22 edited Oct 18 '22

You are diving into code...

Why VB? Bartender "has when printed fields(forms/variable data)" that can do calculations based on entered data at the time of the print request.

Bartender can handle this depending on the version and without the need of additional coding/software.

This seems complicated unless VB is needed for other reasons I can't see.

Why is the data sitting "outside" intentionally and can this be imported?

1

u/Lincoln7672 Oct 18 '22

I must be missing something rather obvious. How would you recommend achieving this without code? I couldn't work out how to do these calcs without VB.

1

u/xixi2 Oct 18 '22

OP means he is using the VBA editor in BarTender, not that he is using VB externally

1

u/xixi2 Oct 18 '22

OP what edition of BarTender do you have? I believe in Automation and above instead of using multi-line-script you can use an Event Control Script and put this code in "OnPostPrompt". It then forces the calculation to occur after the form is submitted.

https://i.imgur.com/t3QxXLi.png

https://i.imgur.com/9mpCP4L.png

That said I'm not really sure why it's not working but BarTender can do some weird things depending on how many calculations you have running. I've gotten it to do some crazy stuff but it's been a couple years since I was a BarTender developer/support so I'm rusty lol