Product: LABELVIEW, CODESOFT
Version: LABELVIEW Gold and All Versions of CODESOFT 2014 and Later
This article explains how to use Visual Basic scripting to dynamically show or hide objects during printing based on the value of a variable. In this example, a text object is displayed when a specific variable value is detected, while a barcode object is hidden. If the variable does not match the specified value, the barcode remains visible and the text object is hidden.
Configure Object Visibility Using Visual Basic Scripting
1. Create or open a label that contains at least two objects. In this example, a text object and a barcode object are used.
The text object is linked to a When Printed variable named Text. Verify that the text object is linked to both the When Printed variable and the text object named Text1.
The text object is linked to a When Printed variable named Text. Verify that the text object is linked to both the When Printed variable and the text object named Text1.
2. Navigate to File → Properties and select the Visual Basic Scripting tab.
Enable the checkbox labeled "Activate event call" if it is not already enabled.
Select the subroutine: Sub OnBeforePrint...
Enable the checkbox labeled "Activate event call" if it is not already enabled.
Select the subroutine: Sub OnBeforePrint...
3. Click OK to save the script configuration.
When the label is printed:
When the label is printed:
- If the value in the When Printed variable is exactly "Test1", the text object becomes visible, displays the value "Test1", and the barcode object is hidden.
- If the value does not match "Test1", the text object is hidden and the barcode object remains visible.
Result: Object visibility is controlled automatically during printing based on the value stored in the When Printed variable.
