Incompatible Types Problem While Trying Incrementing Serialnumbers Unsing Vb Scripting
I'm trying to print a range of serialnumbers.
So I made a lable, that contains a form and 3 datasources.
In the form I would like to enter the frist serialnumber.
The three datasources are
'myNumber' - an internal datasource (Number)
'vbForm' - a vb-script (Number) that put the textfiled-Value into the internal datasource
'vbLable' # a vb-script (Number) that puts the value from the internal datasource into the lable textfield, afterwards that I tried to increment the number, but I got a 'incompatible types' script error
So where do I go wrong?
Find a sample bartender document attatched.
Thanks and Regards,
Crazy
[attachment=1685:BarTender-Test.btw]
EDIT:
Here is the code I'm running in vbLabel.OnNewRecord:
Dim test
'Ausgeben
test = Format.NamedSubStrings("myNumber").Value
Value = test
'Inkrement & Speichern
'<THIS INCREMENTING PART BELOW DOSN'T WORK> -> Error#6900 "Incompatible Types"
'test = test + 1
'Format.NamedSubStrings("myNumber").Value = test
I also get an error while trying to convert 'Format.NamedSubStrings("myNumber").Value' into an Integer using CInt()-Function.
-
You cannot add a number to a string. This won't work in VB6 either.
Having a look on your code you can see, that you have a variant that is set to a string. Thus this variant will be allocated as a string in its safearray-structure.
then you direct cast this test to value. Value is always a string (as far as i have figured it out).
After this you try to add "+1" to a string what is usually made by the ALU. This arithmetical logical unit is not able to add a number to an string but only numbers to numbers and therefore you'll get an invalid cast exception which is in Visual Basic Error 6900.
So the way you can change this is to use a type converstion like
test = cInt(test) + 1
However, Visual Basic is not that intelligent. Having nothing in the Textbox means a conversion of the content "Nothing" to a Number. Which number is representing "Nothing"? Right - nothing. And that is the reason why you get this error.
Simply initialize your textbox with something plausible like "0" and it will work.
0
Please sign in to leave a comment.
Comments
1 comment