'add' Function Follow

0
Avatar
Legacy Poster

Hi Team Seagull,

 

it's again time for a question and i'm sure you will be able to help me!
I have this vbscript on a field in Bartender 9.4.


Value = Value + Format.NamedSubStrings("expirationplus").Value

 

Value is something like 1Q12 which comes from the data entry dialogue. I have set Truncation to discard 2 characters on left.

So value is 12

 

'expirationplus' is the name of a database field (text file) where i get a number that is either 5,12 or 20.

 

So what i want to have is that the Value is e.g. 12 + 20 = 32

What happen is that i get 1220. So it's no addition but concentation.

 

So wat i tried is this:
Value = CDbl(Value) + Format.NamedSubStrings("expirationplus").Value
This works in the script assistant, there i'm getthing now the expected value of 32.

 

But when printing the label i'm getting this error message:

Error Message #3907

OnProcessData (Line1): : incompatible data types 'CDbl'
(I have translated the "incompatible data types" error from german to english. Although Bartender is setup in english, this part of the error was in german, obviously taken from the operating systems language. So i'm not 100% sure about the exact message)
 

Well it doesn't matter if i try with singe or double or whatsoever. It works in the Script Assistant but not when printing.

So how can i actually add and not concentate these two numbers?

2 comments

0
Avatar
Fernando Ramos Miracle
Moderator
Comment actions Permalink

As the information from the "expirationplus" name data source is coming from a database field of "text" type you will probably need to apply a numeric conversion to it too. I would suggest you use CInt() instead of CDbl() to avoid decimals. Your code would look as follows:

 

Value = CInt(Value) + CInt(Format.NamedSubStrings("expirationplus").Value)

 

If you are using the data from a database why don't you use a reference to a database field directly? If you want to get only the rightmost characters of the data you could add the Right() function to your code.

 

*The reason why you  don't get an error when testing is because you code is using the default value of your "expirationplus" named data source instead of the data from the database, as at that time no information from the database is being loaded. For instance if you use a direct reference to the database field you'll get an error when testing, as BarTender won't have access at that point to the database, only when printing or doing a print preview.

0
Avatar
Legacy Poster
Comment actions Permalink

Hi Fernando,

yes that did the trick. But there was an additional problem. I had a deeper look at it and noticed that this field was not updating at all with the information entered during printing time.
So Value was always using the standard value. The Value from the database was ok.

So i deleted the field and created it again as i was not able to find the problem within the field. And now it just works! :)
 

Thank you very much!

Please sign in to leave a comment.