Fix errors when executing scripts with VBScript or Python variables

Official translation unavailable. Translate this page with Google:

Problem

You write VBscrip or Python code using label variables. When your Nicelabel solution runs the script, you get an error message about missing variables or values not being set.

The error occurs because of optimization and performance reasons. Only initialized variables load when you run NiceLabel applications. All other variables have no values so in some cases, scripts can't execute. In Automation, your script often uses variables from triggers' data which are also not initialized.

Solution

By default, NiceLabel variable values load conditionally and variables are not used/called until later in runtime. PowerForms initializes label variables and script variables, but not the variables used in forms. Automation initializes only script variables.

With these solutions, you initialize all your variables at beginning of script executions.

Solution 1

Note

This method applies to all your NiceLabel solutions and scripts. If you want only selected scripts to initialize all variables (because of performance reasons), see Solution 2 or Solution 3.

Edit product.config XML file:

  1. Navigate to the NiceLabel System folder.

    %PROGRAMDATA%\NiceLabel\NiceLabel 10

  2. Create a backup copy of product.config file.

  3. Open product.config file in a text editor. The file has an XML structure.

  4. Add the element IntegrationService/UseAllVariablesForScripting with value True.

    The file should have the following contents:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        ...
        <IntegrationService>
            <UseAllVariablesForScripting>True</UseAllVariablesForScripting>
            ... 
        </IntegrationService>
        ...
    </configuration>
  5. Save and close product.config file.

Solution 2
  • For VBScript:

    Add the comment at the beginning of your script:

    'NL-LoadAllVariables

  • For Python:

    Add the comment at the beginning of your script:

    #NL-LoadAllVariables

    Example 1. Example:

    Code that causes an error:

    list_invert.Value = ",".join(str(x) for x in [y for y in [z for z in range(1, int(last_row.Value) + 1)] if y not in [int(element) for element in selected_rows.Value.split(",")]])

    Variables last_row and selected_rows do not have values until later in execution.

    Code that works:

    #NL-LoadAllVariables

    #Keep comment above to pre-load all NiceLabel variables

    list_invert.Value = ",".join(str(x) for x in [y for y in [z for z in range(1, int(last_row.Value) + 1)] if y not in [int(element) for element in selected_rows.Value.split(",")]])


Solution 3

Manually initialize your variables.

Variable123.Value = Variable123.Value

or

v123 = int(Variable123.Value)

Example 2. Example

Code that causes errors:

list_invert.Value = ",".join(str(x) for x in [y for y in [z for z in range(1, int(last_row.Value) + 1)] if y not in [int(element) for element in selected_rows.Value.split(",")]])

Variables last_row and selected_rows do not have values until later in execution.

Code that works:

last_row.Value = last_row.Value

selected_rows.Value = selected_rows.Value

list_invert.Value = ",".join(str(x) for x in [y for y in [z for z in range(1, int(last_row.Value) + 1)] if y not in [int(element) for element in selected_rows.Value.split(",")]])

or

lr = int(last_row.Value)

sr = selected_rows.Value

list_invert.Value = ",".join(str(x) for x in [y for y in [z for z in range(1, lr + 1)] if y not in [int(element) for element in sr.split(",")]])