该函数需要将通用列表(Byte())作为agrs传递,我似乎无法将任何内容添加到此列表中。我需要printdata(0)& (1)加入它。
Dim printdata(1) As String
labelname = "WasNow"
printdata(0) = "9,99"
printdata(1) = "6.99"
Dim args = New List(Of Byte())
args.Add(Convert.ToByte(printdata))
ApplicationContext.CurrentDevice.Printer.Print(labelname, 1, args)
Frmscanprint.Show()
这是代码的工作C#版本,只需要添加一个项目。
private void printButton_Click(object sender, EventArgs e)
{
try
{
this.printNumber++;
var args = new List<byte[]>() { Encoding.ASCII.GetBytes(string.Format(CultureInfo.InvariantCulture, "Test #{0}", this.printNumber)) };
if (!ApplicationContext.AllDevicesSelected)
{
ApplicationContext.CurrentDevice.Printer.Print("SamplePrint", 1, args);
}
else
{
PrintSampleForEachDevice("SamplePrint", 1, args);
}
}
}
答案 0 :(得分:1)
您提供的C#示例获取单个字符串并将其转换为字节数组,并将此数组分配给新创建的列表。
你的代码没有做同样的事情。您正在尝试将字符串数组转换为字节数组。您尝试使用的方法不允许使用此转换类型。即使有可能,结果也会是包含整个内容的单字节数组,而不是字节数组的数组。
如果你想做与C#代码相同的事情,你应该从你的字符串数组中为每个itm做一次。
如果你想做与C#代码相同的事情,你应该为你的字符串数组中的每一个项目做。例如:
For Each item As String In printdata
args.Add(Encoding.ASCII.GetBytes(item))
Next