Knowledge Base

Defining object visibility and Controlling conditional objects

Problem

With NiceLabel software it is fairly easy to control the visibility of label objects, or to define the conditional objects that appear when some condition is met. Many times using the conditional objects is just a matter of out-of-the-box functionality, for more complex conditions you can utilize the Visual Basic scripting in a very simple form (just a few lines of the code).

Using conditional objects in NiceForm application builder is even easier through the action Set object property.

Solution

CONDITIONAL OBJECTS IN NICELABEL PRO

Displaying or hiding the objects on the label becomes important issue when solving label-printing problems in more complex environments, where labels with variable objects are in use. Label objects (text, text box, bar code, etc.) are linked with some variables, which get values from database, can be result of some calculation, the user can enter data etc. Based on the provided product ID NiceLabel prints the label. However, the same label template can be used for many different products, where not all products will provide data for all label fields.

For example: for product A the label must print with the description and color code, but for product B we need just the description, but no color code.

To display or hide object on-the-fly in NiceLabel, just use the simple rule that NiceLabel follows with variable objects. If the variable is empty (does not have any contents), the object linked with this variable will not appear in the label. Using this rule you can effectively control the appearance of objects on the label. If you do not want to print color code for the above product B, just make sure the variable that provides the color code will have no value. If you use the database, then the record will have no value for product code.

DETAILED OBJECT VISIBILITY

However, sometimes you will receive a data also for the object that you do not want to print for some particular object. For example, you always receive the information about the product code from your database, even if you do not want to use it for product B.

NiceLabel allows you to programmable determine the conditions you want to trace and then decide to display or hide the object on the label. This approach requires Visual Basic scripting and some basic programming skills.

The necessary steps are the following:

  1. Create a new VB script function in Data -> Functions -> New -> Visual Basic Script.
  2. Click the Build script button to go to the code editor.
  3. Enter the VB script, something like:
    Dim a
    if ProductID="ProductB" then
      a = label.SetObjectVisible("ColorCode",False)
    else
      a = label.SetObjectVisible("ColorCode",True)
    end if

    Where:
    - Product ID: a variable that defines the product. We use it to determine if the user requested printing label for product B.
    - ColorCode: name of the object that will print the colorcode information on the label.
  4. If variable ProductID has value ProductB, the object with the name ColorCode will not display on the label, even if the variable ColorCode has a value.
  5. The function label.SetObjectVisible requires the name of the object, which should display or be hidden. Each label object must have a unique name.
  6. To define name of the object, see the option object properties -> Appearance tab -> Advanced button -> Object Name.

    Note: You can also use Label Inspector to rename the object. This is 'property editor' for label objects. Enable it in View -> Label Inspector.
  7. Make sure tu put the result of the VBScript on the label. Bind the function-generated variable with the Text object on the label. Make the Text object non-printable. This way the VBScript will execute, but its result will not be visible on the label.
    If you don't use VBScript result on the label, NiceLabel Pro will ignore the functions as its result is not in use anywhere.

ADDITIONAL USEFUL INFORMATION

CONDITIONAL OBJECTS IN NICEFORM

Using conditional objects in NiceForm application builder is even easier as no scripting is necessary. You can control the object visibility using the built-in action Set object property.

For each NiceForm object that you want to hide in the form, set the property Visible to False.

The other object properties (next to Visible), are Left, Top, Width, Height, Enabled, Color, Font color, Font name, Font size, and Font style.

Print document   Email document

Feedback

Did this article help you? *