VB Type Mismatch Error
Hi everyone,
Hoping someone can help me with a problem I'm finding with a type mismatch error!
I have a label pulling data from two different sources. There is a table linked to an Excel spreadsheet which is giving the value in the field of "BW", and then some values linked to our SQL database giving the "PW" value. The value for "Qty" is an input via a form.
I'm trying to combine these values in a calculation for a new item to show on the print, and my script is currently as below:
Dim v1, v2, v3
v1 = Format.Objects("BW").Value v2 = Format.NamedSubStrings("Qty").Value
v3 = Format.NamedSubStrings("PW").Value
value = Round(v1 + (v2 * v3),2)
I'm getting the below error:
OnPostPrompt (Line 5): Type mismatch: 'v1'
Any help would be much appreciated!
-
Peter Thane
★ BarTender Hero ★
Have you tried adding an Int command to each of the lines?
ie v1 = Int(Format.Objects("BW").Value v2 )
0 -
Jenna Pearce
★ BarTender Hero ★
Hi Peter,
I did try this initially but the problem is that the values I'm calculating are weights and I need to display them to 2 decimal places unfortunatley!
Thanks,
Jenna
0 -
Peter Thane
★ BarTender Hero ★
If you make sure the fields have some numeric default values and remove the DIM line then it should work as it is
0 -
Jenna Pearce
★ BarTender Hero ★
Hi Peter,
No luck unfortunately :(
0 -
Peter Thane
★ BarTender Hero ★
You need to use Format.NamedSubstring not Format.Objects for the v1 command
0 -
Jenna Pearce
★ BarTender Hero ★
I can't pull the value from the embedded table if I use NamedSubstring, the only way I can get the value to pull through is to use Format.Objects. I have already tried this with Format.NamedSubstring for everything.
0 -
Peter Thane
★ BarTender Hero ★
Is it a Database field too and so could you reference it from their instead? If not what type of field is it on the label?
0 -
Jenna Pearce
★ BarTender Hero ★
I have two types of fields on the label. The two items shown as a NamedSubstring are database fields, from a linked SQL database. There is then a linked database pulling data from an Excel spreadsheet, generating the BW field via a table. The only way I seem to be able to extract the value from this table using VB is with the Format.Objects coding.
0 -
Peter Thane
★ BarTender Hero ★
Not tried doing what you are doing but you try and add an additional text field onto the label and link that the to the BW field (say via the Object Print Method) and then, having named the field, link to that in the VB with the Format.Named
Not a table object but for a text item using Format.Objects, to perform the maths functions I had to either convert it to an Integer (Int command), which I know you cant use or else add a Round command in for that object first, as shown below
0 -
Jenna Pearce
★ BarTender Hero ★
That seems to have helped a bit but not fully solved it! I now don't get an error in the VB script editor and when I test the script it doesn't show any errors. However when I go to print a label it still gives the same error:
0 -
Peter Thane
★ BarTender Hero ★
Does the data in the database include the weight symbol? ie 10.5 KG etc
The error is saying the data in the database is not numeric and so cannot process it. You configure the Truncation>Character Filter>Numeric Only for field 28 then that should get round this but this may mean you need to add another string (or substring) that has the weight symbol in it
0 -
Jenna Pearce
★ BarTender Hero ★
Hi Peter,
Unfortunately not!
The weight from the table is shown below. I've also tried with the Box Weight field in red which is a separate field, taking the same data as from the table.
0 -
Peter Thane
★ BarTender Hero ★
Are you still using the format.object route? As I wonder if this is still the issue. Or when are you processing the VB? You may need to set as an Event Controlled VB routine, possibly OnNewRecord or OnPostPrompt so that it runs using the data pulled from the tables.
0 -
Jenna Pearce
★ BarTender Hero ★
Hi Peter,
Yes still using format.object.
It's OnPostPrompt at the moment.
Would it be too cheeky of me to suggest if you have time we could perhaps have a Teams call? I really appreciate your help and support and wonder if it might be easier if we can share the screen live!
Jenna
0 -
Peter Thane
★ BarTender Hero ★
Sorry, been away and just checking this would be okay with the guys at Seagull.
0 -
Hey all! Our Forum's policies don't permit us to share personal information here. However, if Jenna is OK with it, we could send her Peter's personal information via email. :)
0 -
Jenna Pearce
★ BarTender Hero ★
Hi both, that would be amazing if you could!
0 -
You should have Peter's details in your inbox. If not, please let me know :)
0
Please sign in to leave a comment.
Comments
18 comments