Tips and Tricks Using VBScript in NiceLabel
Article ID: 186 - Updated: Jan 25, 2021 - Products: Automation, Designer PowerForms, Designer Pro, SDK, Web printing - Version: Any - Category: Compatibility and Migration
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 are:
- Complex check digit calculations.
- Decision making: conditional executing actions.
- Exchanging data with SQL server.
- Controlling external devices.
NiceLabel Pro, PowerForms and Automation provide the Visual Basic Script (VB script) support to enhance NiceLabel with features not initially planned in the software.
NiceLabel supports the syntax of the VB script language, but with some limitations.
If NiceLabel displays an error in VBscript, verify the following:
1. Convert variables to numeric (CInt) when doing calculations.
NiceLabel applications look at the variables as string values. Even if you define variables as numeric, NiceLabel prevents you from entering non-digit characters. The values are interpreted as strings.
Convert your variables to Integer or Long Integer with the function CInt.
2. Assign the values to your variables at the beginning of VB script
If the variables are empty when you execute the VB script, the script validation fails.
Define the variable values directly in the script.
To check your variable values and execute statements, use a code like this:
If Myvariable <> "" Then
Write such code for all your variables.
3. Enclose the variables in square brackets, if they include spaces in their names.
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 their names.
4. Enclose your variables/database field names in square brackets, if they contain reserved names.
When you write SQL sentences, enclose your variable/field names in square brackets, even if the names do not include spaces. This ensures that the SQL server sees the variable/field as such, and not as the reserved names of SQL functionalities.
For example, your field's name is FIELD. This is the reserved name and you should avoid it. If you use it anyway, 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 you solution. The output VBscript functions are function-generated variables. To test that VBscript function executes, place a text object with your function variable on the label or form.