How to remove only specific leading characters
I will preface this with I know very little about VB Scripting beyond using it in Excel and even then, I am pretty limited.
I have Item numbers that have one of three specific special characters that I want to remove from the barcode label. I cannot use the Alphanumeric Only filter as some Numbers will have a '-' dash in them and the filter will strip those away.
Real life EXAMPLES:
#K6201-5589 should be K6201-5589
*K6201-8859 should be K6201-8859
-K8846-0112 should be K8846-0112
Thank you in advance for any help given.
-
Peter Thane
★ BarTender Hero ★
If it is the leading digit for all the codes then you could just use the Transforms>Truncation and discard the leading character
0 -
Troy Harkness
★ BarTender Hero ★
Unfortunately, not all the characters are the leading digit on all Item Numbers. Some of the Item Numbers start with a number or letter. The special characters will show up in the middle of the Item Number as well but the characters in the middle need to stay there and not get stripped out.
0 -
Peter Thane
★ BarTender Hero ★
So it looks like you are wanting to do something like this
To do this you will need to add some VB that looks for the *, or - or # as starting characters only and strips them off and this does the trick:
Value = Format.NamedSubStrings("NoOne").Value
Value1 = Len(Value)
Value2 = Value1-1
Value3 = Left(Value,1)
If Value3 = "#" then
Value = Right(Value,Value2)
elseif Value3 = "-" then
Value = Right(Value,Value2)
elseif Value3 = "*" then
Value = Right(Value,Value2)
else Value = Value
end if
Value = Value
The first line should be replaced by linking the Value = command to the field that has the full number in it, either as a Named source like I am using or else a Database field that will appear in the Script Assistant column box if your label is connected to a database. Note, for the Named data source option the field does not have to be on the printed label but can be added to the side of the printed area and so the VB can reference it even if you don't want the full value printed.
1 -
Troy Harkness
★ BarTender Hero ★
I am obviously using an older version of bartender 10.0 if that matters.
I have tried a few different combinations trying to get this to run. No matter what I try to place in the Format.Substrings("NoOne").Value I get basically the same error. It calls out whatever I place in it as not found in the Named Data Sources. I have included the named Data Sources to see it. There is nothing in it.
0 -
Peter Thane
★ BarTender Hero ★
You would need to create the Named Data Source first (or at least give the field a name). I think that option maybe on the Data Source tab of the Text Properties screen but I could be wrong as it is has been a number of years since I last used v10.0. Saying that as I think you are linking to a database field then you wont need to do this as you can reference the DB field from the Category list at the bottom of the VB screen. However, you are using the wrong VB option I believe as you are applying the VB to the data not manipulating the data to suit, if that makes sense.
The Data Source of the field needs to be Visual Basic Script and not Database and then the "type" (I think it is) should be set to Event Controlled Script and OnNewRecord so that the VB is applied when a new database record is selected. The code can then be pasted into the similar box to the above with line one edited to select the right database field
0 -
Troy Harkness
★ BarTender Hero ★
I was able to get the label files into the newer version of bartender. The script worked as you described. Saved the file as older version 10.1 and the script did no longer worked.
Troy
0 -
Troy Harkness
★ BarTender Hero ★
Never mind it did work. Sorry for the miss leading message above. I was not outputting the file to see the result. I was relying on the hardcoded info I used as sample data on the label. When I ran it through to print preview it worked.
Thank you for all the help.
Troy
0
Vous devez vous connecter pour laisser un commentaire.
Commentaires
7 commentaires