Trying to set a variable with another one

Issues related to label design (working with databases, data processing, RFID encoding etc.) and printing (from NiceLabel Express, NiceLabel Pro, NiceForm and NicePrint)

Moderators: Georges, milos, NiceLabel Support Team

Post Reply
depfuell
Newcomer
Posts: 4
Joined: Tue Sep 03, 2019 12:01 pm

Trying to set a variable with another one

Post by depfuell » Tue Sep 03, 2019 12:15 pm

Hello,

I'm trying to design a label for a carton lable application. We have different customers and i like to select the customer at the printing dialog via a dropdown field. I set them in the variable "customername". Now depending on the customer you select, the variable "customershortcut" should set to a specific value. Therefore I wrote a VBScript, but i get an error during the printing dialog. "object nessesary: 'label'"

Code: Select all

Dim cn	
dim cs

cn =[Customername]
cs =[customershortcut]

if cn = "Golf" then
    result = label.variables.findbyname("customershortcut").setvalue("go%")
 end if
I like to use the variable customershortcut to filter an excelsheet.
I attached a smal example.

Can somebody help me?
Attachments
Testlabel11.nlbl
(3.92 KiB) Downloaded 14 times

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

Re: Trying to set a variable with another one

Post by Mytch » Tue Sep 03, 2019 11:57 pm

depfuell,

This script will fail in NiceLabel 2017 or NiceLabel 2019, because the label object no longer exists. NiceLabel 6 supported ActiveX API integration, which allowed modification of label objects through VBSript. ActiveX is soon to be entirely deprecated and no longer supported by Microsoft, so we have decided to remove the integration from NiceLabel. Please see this article regarding the differences between NiceLabel 6 and NiceLabel 2019:
https://www.nicelabel.com/support/knowl ... icelabel-6

We have some information here about the removal of ActiveX API. In this case, we recommend to find an alternate Solution. Variable names can be simply set in VBScript using syntax like [VariableName] = "newscriptedvalue".

Regards,
Mytch

depfuell
Newcomer
Posts: 4
Joined: Tue Sep 03, 2019 12:01 pm

Re: Trying to set a variable with another one

Post by depfuell » Wed Sep 04, 2019 2:48 pm

Dear Mytch,

thank you very much for this information. I solved the problem.
Variable names can be simply set in VBScript using syntax like [VariableName] = "newscriptedvalue".
This was the info I searched for. I have one more question. I tryed the following code wich doesn't work.

Code: Select all

cn =[Customername]
cs =[customershortcut]

if cn = "Golf" then
   cs = "go%"
 end if
When I changed it to the following code it works. Can you tell me why?

Code: Select all

cn =[Customername]
cs =[customershortcut]

if cn = "Golf" then
   [customershortcut] = "go%"
 end if

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

Re: Trying to set a variable with another one

Post by Mytch » Wed Sep 04, 2019 7:01 pm

depfuell wrote:
Wed Sep 04, 2019 2:48 pm

Code: Select all

cn =[Customername]
cs =[customershortcut]

if cn = "Golf" then
   cs = "go%"
 end if
When I changed it to the following code it works. Can you tell me why?

Code: Select all

cn =[Customername]
cs =[customershortcut]

if cn = "Golf" then
   [customershortcut] = "go%"
 end if
depfuell,

Well there are no issues with syntax, so I assume by "not working" you mean that variable "customershortcut" does not get set to "go%" in the first script, but it does set properly in the second. This is expected based on your script logic, because setting cs = [customershortcut] does not inherently mean that NiceLabel variable "customershortcut" is the same as VBScript variable "cs".

In other words, the first script you start by setting cs = [customershortcut], so this means "cs" now has the value of "customershortcut". Then, you set cs = "go%", so "cs" now has the value of "go%", but "customershortcut" still is unchanged. Again, cs = [customershortcut] does not imply that the values are the same at all times.

In your second script, things work properly because you are actually setting the "customershortcut" variable to your desired output, which is to be displayed on the label/form. Hopefully this makes sense.

Regards,
Mytch

depfuell
Newcomer
Posts: 4
Joined: Tue Sep 03, 2019 12:01 pm

Re: Trying to set a variable with another one

Post by depfuell » Thu Sep 05, 2019 12:04 pm

Mytch,
Hopefully this makes sense.
Thanks so much now i got it.

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

Re: Trying to set a variable with another one

Post by Mytch » Thu Sep 05, 2019 4:17 pm

depfuell wrote:
Thu Sep 05, 2019 12:04 pm
Mytch,

Thanks so much now i got it.
Great :) Thanks for the update.

johnharis
Newcomer
Posts: 1
Joined: Fri Sep 06, 2019 9:26 am

Re: Trying to set a variable with another one

Post by johnharis » Fri Sep 06, 2019 9:29 am

Thanks for sharing!
Mytch wrote:
Tue Sep 03, 2019 11:57 pm
depfuell,

This script will fail in NiceLabel 2017 or NiceLabel 2019, because the label object no longer exists. NiceLabel 6 supported ActiveX API integration, which allowed modification of label objects through VBSript. ActiveX is soon to be entirely deprecated and no longer supported by Microsoft, so we have decided to remove the integration from NiceLabel. Please see this article regarding the differences between NiceLabel 6 and NiceLabel 2019:
https://www.nicelabel.com/support/knowl ... icelabel-6

We have some information here about the removal of ActiveX API. In this case, we recommend to find an alternate Solution. Variable names can be simply set in VBScript using syntax like [VariableName] = "newscriptedvalue".

Regards,
Mytch

Post Reply