Shared Vb Script Function
Hi,
is it possible to reuse script functions?
Can you store a function somewhere in a document or on a control and call that function from eg another control?
example:
Function ReplaceXYAB(val)
val=Replace(val,"xy","56")
val=Replace(val,"ab","34")
ReplaceXYAB=val
End Function
text control on label with text 1234xy6789, with transformation VB script OnProcessData : Value = ReplaceXYAB(Value)
barcode control on same label with text 12ab56789, with transformation VB script OnProcessData : Value = ReplaceXYAB(Value)
Or is this only possible when creating components?
thank you,
regards,
Tom
-
Shotaro Ito
★ BarTender Hero ★
Hi Tom,
Data source's vb script doesn't have an access to other data source's script, neither to document option script.
That makes Functions and Subs cannot be shared in between objects.
Components are just one or a group of objects, so the same apply to components.
(It's still handy if you have some frequently used scripts as components, though).
Besides, VB Script has a statement Execute. You could keep functions in a named data source.
Then each data source, register by
Functions and Subs:
Execute(<Share name>)
like attached sample.
I recon this is a crude approach - the functions are not really shared, just run the same code every time.
0 -
Shotaro Ito
★ BarTender Hero ★
There's a similar requests in another post - I've add one more to the feature request.
0 -
Hi Shotaro,
thank you for the clarification, good to know it might be a future feature.
I resolved my issue by creating 2 components, one for text and one for barcode.Each has it own copy of the same script function.
Untill the shared script library feature, this will work fine.
0 -
TomL's question is similar to the one I'm just having...
So there's no "global" label-wide scope for VBScript such that any variables/functions/subroutines declared and defined there will be usable by all VBScript placed on controls/label-parts?
On the Transforms tab on each control/label-part there is the "VB Script" transform...
It has a "Functions and Subs" event type... which is described as:
"Shared subroutines, functions, and variables are placed here for reference by other events."
Does this mean any code placed here is only visible to other events on this specific control/label-part?
And so reiterating my question... there's no "label-wide" scope with events applicable to the whole label?
0 -
Shotaro Ito
★ BarTender Hero ★
Hi Thorpe,
Functions and subs on datasource VB script can be shared within the same datasource - shared in between events.
The label-wide scope action can be done from File > BarTender Document options > VB Script.
However functions and subs in document option script cannot be accessed from datasource vb scripts.
(note this is supported from BarTender 9.3 Automation Edition or above.)
0
Please sign in to leave a comment.
Comments
5 comments