VB Script not calculating sum of fields
Hello,
New to this.
I am having an issue with VB calculating the sum of other fields.
Issue : As long as I have a value in every Quantity field the calculation worked properly, however, if a field did not have a value I would get an error when trying to preview or print. Found a post to help with this by adding the following:
If value="" then
value=0
end if
When I added this, now it does not calculate the sum, it list each value side-by-side in the Total field.
I have added the script and an image of the output.
I appreciate any assistance.
Below is the script:
value1 = Format.Objects("Qty1").Value
If value="" then
value=0
end if
value2 = Format.Objects("Qty2").Value
If value="" then
value=0
end if
value3 = Format.Objects("Qty3").Value
If value="" then
value=0
end if
value4 = Format.Objects("Qty4").Value
If value="" then
value=0
end if
value5 = Format.Objects("Qty5").Value
If value="" then
value=0
end if
value6 = Format.Objects("Qty6").Value
If value="" then
value=0
end if
value7 = Format.Objects("Qty7").Value
If value="" then
value=0
end if
value8 = Format.Objects("Qty8").Value
If value="" then
value=0
end if
value9 = Format.Objects("Qty9").Value
If value="" then
value=0
end if
value10 = Format.Objects("Qty10").Value
If value="" then
value=0
end if
value11 = Format.Objects("Qty11").Value
If value="" then
value=0
end if
value12 = Format.Objects("Qty12").Value
If value="" then
value=0
end if
Format.NamedSubStrings("TotalQTY").Value = (value1+value2+value3+value4+value5+value6+value7+value8+value9+value10+value11+value12)
Image of output:
-
Paweł Gancarz
★ BarTender Hero ★
Hello David,
I gave the objects to text, and the sum to numbers with two decimal places.
Below you have pictures of what it looks like.One line script
value=int(Format.Objects("A1").Value)+(Format.Objects("A2").Value)+(Format.Objects("A3").Value)+(Format.Objects("A4").Value)+(Format.Objects("A5").Value)+(Format.Objects("A6").Value)+(Format.Objects("A7").Value)+(Format.Objects("A8").Value)
Add a condition to each object as it will be empty to insert zero
As you wrote in your query
IF Value="" then
value="0"
end if0 -
Peter Thane
★ BarTender Hero ★
It should be if...then...else I believe and so you would need an
else valueX = valueX
for every value
ie
value1 = Format.Objects("Qty1").Value
If value="" then
value=0else value1 = value1
endif
0
Please sign in to leave a comment.
Comments
2 comments