DataType Mismatch
When previewing and testing this script works fine. When printing i always get a mismatch error that i can click continue on and it works, but i want to get rid of the error
The value read from DB is in all inches. I convert to feet/inches for printing on the tag.
IF Value <> "0" OR Value <> " " THEN
Inches = Value
Feet = Inches \ 12
Inches2 = Inches - (Feet * 12)
Value = Feet & Chr(39) & " " & Inches2 & Chr(34)
ELSE
Value = ""
END IF
-
Joe Sorensen
★ BarTender Hero ★
Bartender Automation 10.1 latest service release
Message box states
Bartender: Error Message #3907
The following script error occurred:
OnProcessData(Line 4): : Type mismatch: 'Inches'0 -
KM3
★ BarTender Hero ★
How do you get the data into the script (from the DB)? Make sure the value you get from the DB really is a number (maybe use IsNumeric(Value) to check this as a test). I don't really see how the script executes correctly and gives you the correct result despite the error message...
Also, you may be able to more easily get the remainder in line 3 and 4 using the Mod operator: https://msdn.microsoft.com/en-us/library/basszbdt(v=vs.84).aspx
0 -
Joe Sorensen
★ BarTender Hero ★
A query prompt accepts a scanned sales order number from paper form, using that query prompt as a WHERE clause, a query return a row/rows of sales order lines which is used as record for tag output.
Below is a screen shot. The information in the field will be 0 if the object contains no width or no length, i added the " " in the NOT case just to cover bases. So basically if every value should be caught as no non-numerics can exist in the field.
0 -
KM3
★ BarTender Hero ★
Is there a specific reason this script is located in OnProcessData? I think this may be a problem as BarTender probably tries to execute it at an inconvenient point.
0 -
Joe Sorensen
★ BarTender Hero ★
That's just where I thought it went. That is where is saw vbscript on transform tab and thought it went.
Can you recommend a better way to do this? Used bartender for year but this is my first time scripting anything.
0 -
KM3
★ BarTender Hero ★
You can change the data source type of your object to VBScript. You can then also select between 3 different script types. You can also go to File > Document Options (or similar) and add scripts there. However, you may need to change the script a bit to reference the values you need (e.g. to reference a data source named "mydata", you cannot just reference it with "Value" but you need to write Format.NamedSubStrings("mydata").Value)
0 -
Joe Sorensen
★ BarTender Hero ★
Just tried that. couldn't figure it out.
Would it be easier to send you the btw file and see if you could take a peek? I'd be eternally grateful.
0 -
KM3
★ BarTender Hero ★
I have another idea. Leave everything the way you had it initially. Remove the double quote marks from the 0 in the first line of your script (so it reads: IF Value <> 0 OR...).
0 -
Joe Sorensen
★ BarTender Hero ★
Did that.
Now getting this error. I don't get why it works perfect (no messages) in print preview but not at actual real print time.
Here's the code
IF Value <> 0 OR Value <> " " THEN
Inches = Value
Feet = Inches \ 12
Inches2 = Inches - (Feet * 12)
Value = Feet & Chr(39) & " " & Inches2 & Chr(34)
ELSE
Value = ""
END IF0 -
Joe Sorensen
★ BarTender Hero ★
should mention the information from the data record is exactly the 3 characters five point five '5.5' (without the quotes)
and if i enter through both fields it does print fine. But we're trying to make this a scan and grab kind of deal with no prompts.
0 -
KM3
★ BarTender Hero ★
Ok, I think we're getting closer. Try this:
- You have an object containing a data source which is linked to the database. And in the properties of that data source you have your script active in one of the "Transforms" options, correct? Continue only, if yes...
- Remove the script and all other transform functionality from the data source.
- Give the data source a name, e.g. "db_inches".
- Move the entire object out of the way and set its properties to never print.
- Create a fresh new object at the first object's former place. Set the data source type to VBScript, select "Event Control Script" as script type.
- Open the script editor and in the "OnNewRecord" event, place the script as below.
dbi = Format.NamedSubStrings("db_inches").Value
If dbi <> "" Then
feet = dbi \ 12
rem = dbi - (feet * 12)
Value = feet & Chr(39) & " " & rem & Chr(34)
Else
Value = ""
End If1 -
Joe Sorensen
★ BarTender Hero ★
You are a genius!
Not sure why it wasn't working in the Transform Script, but it works as a vbScript object.
Can i send you some Starbucks?
0 -
KM3
★ BarTender Hero ★
Glad I could help - but I'm definitely not a genius; I should have proposed this solution from the very beginning and I might have, had I actually properly tried to understand the problem.
I don't really know what went wrong but it must have had something to do with how and when the script executed and how/when it stored the enumerated value (or rather: string) - because the script referenced that data source's content itself, it probably backfed the result (feet inches) and so the division didn't work anymore (thus type mismatch, since you cannot do a division on a string). Something like that.
0 -
Joe Sorensen
★ BarTender Hero ★
Not sure if you're still following this thread or not, this formula has been amazing so far, but we encountered one issue and i'm not quite sure what is wrong
we had a length of 95.5 inches.
When run through the formula it calculated 8 feet + negative .5 inches (prints exactly as 8' -0.5") instead of 7' 11.5"
any idea why?
0 -
KM3
★ BarTender Hero ★
It's because the integer division (dbi \ 12) rounds any fractional component before performing the division. I wasn't aware of that myself either. But the result is clear: 95.5 is rounded to 96, which is then divided by 12, giving exactly 8'. In the next line, you effectively subtract 96 from 95.5, giving -0.5".
I think you can solve this by disregarding fractional components (decimal values) before doing that division. Like this:
feet = Int(dbi) \ 12
I did some minimal testing and that should solve it. However, I noticed that when e.g. using an initial inch value of say 8111.11, the result will be 675' 11.1099999999..7", which is close, but may not what you want to have appear on your label.
To solve that, round the remainder to your decired number of decimal places, like this:
rem = dbi - (feet * 12)
rem = Round(rem, 2)0 -
Joe Sorensen
★ BarTender Hero ★
genius still stands :)
Longest length we'd have would be like 80' so i think we're good.THANK YOU!
0
Vous devez vous connecter pour laisser un commentaire.
Commentaires
16 commentaires