Changing Data Using C# フォローする

0
Avatar
Legacy Poster

I wish to change substrings from within C#.

Example:

btFormat.SubStrings["Field2"].Value = "39";
btFormat.SubStrings["Field4"].Value = "4";

where Field2 and Field4 are valid named substring currently changed by an operator using a Prompt with the source selected as Screen Data. It appears my only options for the source do not include C#. Your SDK help files demonstrate using C#, but make not mention of the source selection. How is this done?

Thanks

3 コメント

0
Avatar
Gene Henson
モデレータ
コメントアクション Permalink

Hello,

Does the code below help you with your question? This is an example of updating substring values through the SDK.

If this doesn't answer your question, can you elaborate on what you need?

[code]
public void Demo()
{
// Initialize a new BarTender print engine.
using (Engine btEngine = new Engine())
{
// Start the BarTender print engine.
btEngine.Start();

// Open a format document.
LabelFormatDocument btFormat = btEngine.Documents.Open(@"C:\Format1.btw");

// Display the number of substrings in the format.
Console.WriteLine("SubStrings Count: " + btFormat.SubStrings.Count);

// Iterate through and read each SubString Name, Type and Value.
foreach (SubString substring in btFormat.SubStrings)
{
Console.WriteLine("SubString Name: " + substring.Name
+ ", SubString Type: " + substring.Type
+ ", SubString Value: " + substring.Value);
}

// Set a SubString Value using its index.
btFormat.SubStrings[0].Value = "New SubString Value";

// Set a SubString Value using its name (case sensitive).
btFormat.SubStrings["SubString1"].Value = "New SubString Value";

// Close the current format without saving.
btFormat.Close(SaveOptions.DoNotSaveChanges);

// Stop the BarTender print engine.
btEngine.Stop();
}
}
[/code]
0
Avatar
Legacy Poster
コメントアクション Permalink

No this does not help. In fact I added a btFormat.Print, changed the label to my file in your sample (also commented out the set value by name) it too did not do as I expected.

Here is my code:

using (Engine btEngine = new Engine(true))
{
btEngine.Start();
LabelFormatDocument btFormat = btEngine.Documents.Open(@"C:\Labels\LabelFormats\B4x4_SXxA0_rev1x.btw");

btFormat.SubStrings["Field2"].Value = "39";
btFormat.SubStrings["Field4"].Value = "4";

btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;

Messages btMessages = null;
Result nResult = btFormat.Print("Test1 Print", 6000, out btMessages);

btFormat.Close(SaveOptions.DoNotSaveChanges);
btEngine.Stop();

// Display the print result.
PrintResult += "Print status = " + nResult + Environment.NewLine;

// Print all returned messages.
foreach (Message m in btMessages)
{
PrintResult += "Category = " + m.Category + Environment.NewLine;
PrintResult += "ID = " + m.ID + Environment.NewLine;
PrintResult += "Severity = " + m.Severity + Environment.NewLine;
PrintResult += "Text = " + m.Text + Environment.NewLine;
PrintResult += Environment.NewLine;
}
}

Both "Fields" are normally changed by the operator. Both of these are type 'ScreenData'. What I expected was for the label to print these new values, but they don't. In fact the persistent data (as read before changing) does not print.

So my question is, what 'binds' this type ScreenData to the printer output? Am I missing a command here, or is there another type of data I should be using.

Thanks for your assistance.

Tim
0
Avatar
Legacy Poster
コメントアクション Permalink

I have just found what the problem was. The linkage to the prompt still existed on the Labelformat. Once I removed this, then my code worked as expected.

Thanks for the support.

Tim

ログインしてコメントを残してください。