Changing Data on a Template

BarTender documents may contain named data sources, denoting fields on a template that may be changed. Typically, each data source represents a complete text object, barcode, or RFID tag on a template, although some objects may contain more than one data source. By changing the values of these data sources, you can change the information printed on an item.

Using the NamedSubStrings Collection Object

The NamedSubstrings collection object stores a list of all named data sources that are part of a BarTender document. This collection object allows you to read all of the data source values using the GetAll method , as well as modify the values using the SetAll method. The following example demonstrates how to read the value of a named data source using the NamedSubStrings collection object:

ClosedIn VB.NET

'Declare a BarTender application variable

Dim btApp As BarTender.Application

'Declare a BarTender document variable

Dim btFormat As BarTender.Format

'Create a new instance of BarTender

btApp = New BarTender.Application

'Open a BarTender document

btFormat = btApp.Formats.Open("c:\Format1.btw", False, "")

'Display all of the named data sources

MessageBox.Show(btFormat.NamedSubStrings.GetAll(",", ":"))

'End the BarTender process

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges)

ClosedIn C#

// Declare a BarTender application variable

BarTender.Application btApp;

// Declare a BarTender document variable

BarTender.Format btFormat;

// Create a new instance of BarTender

btApp = new BarTender.Application();

// Open a BarTender document

btFormat = btApp.Formats.Open("c:\\Format1.btw", false, "");

// Display all of the named data source values

MessageBox.Show(btFormat.NamedSubStrings.GetAll(",", ":"));

// End the BarTender process

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

Accessing a Specific Data Source

Named data sources not only can be read, but they can be modified programmatically. The following code demonstrates how to modify a specific named data source using the Format.SetNamedSubStringValue method. This method has two parameters: the first specifies the name of the data source that you want to modify; the second specifies the data source's new value.

ClosedIn VB.NET

'Declare a BarTender application variable

Dim btApp As BarTender.Application

'Declare a BarTender document variable

Dim btFormat As BarTender.Format

'Create a new instance of BarTender

btApp = New BarTender.Application

'Open a BarTender document

btFormat = btApp.Formats.Open("c:\Format1.btw", False, "")

'Set the value of the data source called Name

btFormat.SetNamedSubStringValue("Name", "Jane Doe")

'Set the value of the data source called City

btFormat.SetNamedSubStringValue("City", "Seattle, WA")

'Print the document

btFormat.PrintOut(False, False)

'End the BarTender process

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges)

ClosedIn C#

// Declare a BarTender application variable

BarTender.Application btApp;

// Declare a BarTender document variable

BarTender.Format btFormat;

// Create a new instance of BarTender

btApp = new BarTender.Application();

// Open a BarTender document

btFormat = btApp.Formats.Open("c:\\Format1.btw", false, "");

// Set the value of the data source called Name

btFormat.SetNamedSubStringValue("Name", "Jane Doe");

// Set the value of the data source called City

btFormat.SetNamedSubStringValue("City", "Seattle, WA");

// Print the document

btFormat.PrintOut(false, false);

// End the BarTender process

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

Similarly, you can get the value of a specific data source using the Format.GetNamedSubStringValue method.

Related Topics