A typical scenario for this is when you have an element on a label that needed to be printed only when certain conditions are met. This Instruction Article explains how to programmatically hide or unhide an element in a CODESOFT label.
There are 2 methods of removing (prevent from printing) an element from a label:
- Clear the Data Source
- Visual Basic Script to Toggle the “Printable” Property of the Object
#1 Clear the Data Source
The first method is to clear the content of the element. If it is a text or barcode field, you can simply change the content to blank. However, if the element you want to hide is a picture, thing gets a little bit more difficult.
If you dynamically pull the picture from a file, changing the filename or blank out the filename will do the trick. (see Mustang example in the attached label file). If the picture is embedded into the label, we will have to use the second method.
#2 Visual Basic Script to Toggle the “Printable” Property of the Object
The second method is to use Visual Basic Script to toggle the ‘printable’ property of the element. This solution will, in fact, work for every element type in the label.
The above label has 4 elements:
|Check-Flag||Formula that does all the magic|
|Flag||Data entry field. Use to toggle the elements on/off|
|Mustang||Dynamic graphic element (picture load from a file). The value comes from Check-Flag|
|Truck||Static graphic element|
In Check-Flag, we use a simple formula to set the filename for Mustang:
If (Flag = 1), “Mustang”, “”)
The formula will return the word “Mustang” if Flag has value of 1, otherwise, it will return “” (blank). A blank filename will effectively make the picture disappear from the label.
The script we use is similar to the one in the formula section. Instead of setting the filename, we are changing the “Printable” property of the label element.
if document.variables.Item("flag").Value() = 1 then document.DocObjects("truck").printable = false else document.DocObjects("truck").printable = true end if
The logic is very simple, if Flag = 1then set the Printable for Truck to false, otherwise, set it to True.
The difficulties for this method is to figure out how to address the individual property (Printable) on the label file. The example above shows you how. You can use this concept to manipulate other element’s properties.
Outside Sources and Helpful Links
CODESOFT has a somewhat helpful programmer manual that you can use as reference. It can be found under Help menu.