Knowledge Base

Tips and Tricks Using VBScript in NiceLabel software

Problem

NiceLabel software allows you to adapt to the users's request for functionality not originally available in the software. The typical examples of such requests would be:

  • Complex check digit calculations
  • Decision making: print some object or execute some action only if some condition is met
  • Exchanging data with some SQL server
  • Controlling some external device
  • Etc.

The applications NiceLabel Pro, NiceForm and NiceWatch provide the Visual Basic Script (VB script) support to enhance NiceLabel with features not initially planned in the software.

Solution

NiceLabel supports the syntax of the VB script language, but because of the internal implementation, you must be aware of some NiceLabel peculiarities when using the VB scripting.

When you have troubles in VB script editor and NiceLabel complains about the syntax of your commands, but you do not see any problem in the script, verify the following:

1. Convert variables to numeric (CInt) when doing calculations
NiceLabel applications look at the variables as string values. Even if variable is defined as 'numeric variable', NiceLabel will just prevent the user from entering non-digit characters. The value is still interpreted as string. That's why you have to convert the variable into Integer or Long Integer, whenever you must do some calculations or numerical comparisons on the label.

Use the function CInt.

2. Make sure the variables have some value before you write the VB script
If the variables are empty when you type in the VB script, the script validation will fail and you will not be able to exit the script editor. If you get caught in this situation, define the variable values directly in the script, so that script validation will suceed and you can exit the editor.

Otherwise make sure that you preview the label once, before you start writing the VB script. This action will ensure the label variables will have some value defined.

You can also programmable check for variable value and execute statements only if variable is not empty. Use a code like this:

If Myvariable <> "" Then
    Statements...
End If

3. Enclose the variables in square brackets, if they include spaces in the names
You can use variables, which names include spaces. However, if you want to use them in the VB script, make sure you enclose them in the square brackets. For example, if you have the variable My Variable, use this syntax in the script [My Variable].

If you can choose the variable names yourself, avoid using spaces in the names.

4. Enclose the variables/database field names in square brackets, if they contain reserved names
When you write your own SQL sentence to deal with the SQL databases directly, make sure to enclose the variable/field names in square brackets, even if the names do not include spaces. This will ensure that the SQL server sees the variable/field as such, and not as the reserved name of some other functionality.

For example: your field's name is FIELD. This is reserved name and should not be used. If you insist in using it, you can enclose it in square brackets, [FIELD].

5. Use the function-generated variable VBscript1 on the label
NiceLabel has built-in optimization technique to ignore the functions which result is not used in the label. The output of each function is a function-generated variable (one or more). To make sure VB script function really executes, place the function variable on the label, linked with some object. Complete this step even, if you do not need to print the value. In this case format the object as 'not printable' object.

Print document   Email document

Feedback

Did this article help you? *