Beginner's guide to VB script in 19.2

Label printing integration (NiceWatch middleware and ActiveX programming interface)

Moderators: Georges, milos, NiceLabel Support Team

Post Reply
somebodynew222
Newcomer
Posts: 2
Joined: Tue Apr 28, 2020 3:58 pm

Beginner's guide to VB script in 19.2

Post by somebodynew222 » Tue Apr 28, 2020 4:14 pm

Hello,

I have 20+ years of experience in VB, but am new to NiceLabel.

I've checked out the sample code installed with the software. I have browsed this forum and googled with no luck.
I kinda gather from the forum, that VB Script is more or less obsolete since ver 2017.

I still hope I can make due with VB Script in my case, so here is my question:

I have created a label in Designer Pro 19.2.
I have added two variables:
  • "Inside" - which i bind to a value using a datasource with the 'initial value' option under properties. The object is placed outside the physical label
  • "lblInside" - a display label which is placed on the label design. Default text value is blank.
I have created a function in VB script with the following code:

Code: Select all

'Make sure that all variables used in the script have values.
'The result of the script must be saved in the 'Result'
'variable. Default script will return value "0"

if [Inside]="Non" then [lblInside]="-"

Result = "0"
I used the in-editor feature to 'add datasource', which gave me a rough idea for accessing the objects using brackets.
But when I use the label in NiceLabel Print, the script is either not run or does nothing.

I did manage to find several code examples, where the objects are referenced using a master object such as:

Code: Select all

Result = label.variables.findbyname("Prompt2").setvalue("100")
So, I'm guessing my syntax is way off.
Can someone guide me in the right direction here?

Thanks in advance,

User avatar
Mytch
NiceLabel Support
NiceLabel Support
Posts: 138
Joined: Fri Jul 13, 2018 10:26 pm
Location: Milwaukee, Wisconsin
Contact:

Re: Beginner's guide to VB script in 19.2

Post by Mytch » Tue Apr 28, 2020 11:36 pm

Hi, somebodynew222,

Your provided code is the right way to reference NiceLabel variables with brackets, like [variableName]. The other method referring to label.variable syntax is not supported in NiceLabel 2019. In legacy versions of NiceLabel, Active X could be used for interfacing with label objects. This technology is deprecated and therefore no longer used in NiceLabel 2019.

So you have this function then:

Code: Select all

if [Inside]="Non" then [lblInside]="-"

Result = "0"
This tells me the value of the VBScript function itself is always "0", that's no problem. And this function should also set [lblInside] to "-" if [Inside] = "Non". This syntax should work fine, but most likely there is a problem when the value of [Inside] is changed. Once [lblInside] is set, there is nothing to set its value back from "-" to anything else. So maybe you can solve this problem with something similar to this:

Code: Select all

If [Inside] = "Non" Then
[lblInside] = "-"
Else
[lblInside] = ""
End If
If this does not resolve your problem, then perhaps you can give more info about what your expected result is compared to what you are receiving.

Regards,
Mytch

somebodynew222
Newcomer
Posts: 2
Joined: Tue Apr 28, 2020 3:58 pm

Re: Beginner's guide to VB script in 19.2

Post by somebodynew222 » Thu Apr 30, 2020 11:49 am

Mytch,
Thanks for your reply. It helped me get the script in place.

I am able to verify the VB script is working in the designer. If I manually set the source variable value, the corresponding label value changes due to the script. That part is all ok now.

Unfortunately, the script is not executed at the time of showing the printing dialog. It is neither run on open/show dialog, nor on datasource changes. I had hoped for the latter, since I'm using a SQL datasource to get a table which I use on the design template.

I've looked all over the document properties for at way to enable or engage the script. Is no execution the normal behavior?

Learning as I go, I could simply put my label values into the database table, and just bind them in the editor. Using the show/hide condition options would allow me to accomplish what I need. This means not using a script at all. I'm just wondering if I'm missing something, perhaps a reserved function call like "sub onRecordChange() [do this code]"...?

User avatar
Mytch
NiceLabel Support
NiceLabel Support
Posts: 138
Joined: Fri Jul 13, 2018 10:26 pm
Location: Milwaukee, Wisconsin
Contact:

Re: Beginner's guide to VB script in 19.2

Post by Mytch » Thu Apr 30, 2020 9:24 pm

Scripting functions are 'always running', so there is no need execute them manually. Please be sure that the VBScript Function also exists on the label, otherwise it will not be loaded at print-time. You can control an objects visibility in Properties > General > Visible:
2020-04-30_14h14_49.png
2020-04-30_14h14_49.png (14.52 KiB) Viewed 520 times
In higher editions like PowerForms, you can customize the Print Form and create additional logic/controls. For example, there is a looping action "For every record" that allows you to execute a set of actions for every selected database record. This can include executing a single VBScript function, printing a label, etc.:
2020-04-30_14h16_16.png
2020-04-30_14h16_16.png (20.95 KiB) Viewed 520 times
You may consider contacting Sales for an upgrade if you seek additional control and customization offered with PowerForms:
https://www.nicelabel.com/design-and-controlled-print

To buy or trial:
https://www.nicelabel.com/how-to-buy/contact-us

Regards,
Mytch

Post Reply