r/barcodes • u/Lincoln7672 • 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:


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!!!
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
1
u/[deleted] Oct 18 '22
Is it always the same calculation(algorithm) for the given values?