Comment line in ZPL code
Asked Answered
L

4

6

I want to comment lines in the ZPL code, for example:

^XA
^MMT
^LL0531
^PW1280
^LS0
^FT81,528^A0B,29,28^FH\^FDTEXT^FS               
// ^FT336,495^A0B,29,33^FH\^FDEAN^FS^FX         ----
//^BY3,2,42^FT384,492^BEB,,Y,N                  Commented lines
//^FD789690466123^FS                            ----
^PQ1,0,1,Y^XZ

I want this because sometimes my variable is null and do not want to print the barcode. This is possible? or what the best way to not print the barcode?

Lessor answered 16/10, 2014 at 14:32 Comment(1)
Is there a reason you can't conditionally skip sending the ^BE command?Adhibit
B
8

The short answer is "Can't be done."

The comment-indicator is ^FX after which characters are ignored - but end-of-comment is any ^ or ~ command which makes ^FX next to useless.

Unless there has been a "block-comment" command added, with a specific start/end-block-comment mnemonic-set, then sorry - you're out-of-luck.

All is not quite lost however.

^XA
^FT336,495^A0B,29,33^FH\^FDEAN^FS^FX
^BY3,2,42^FT384,492^BEB,,Y,N
^FD789690466123^FS
^MMT
^LL0531
^PW1280
^LS0
^FT81,528^A0B,29,28^FH\^FDTEXT^FS               
^PQ1,0,1,Y^XZ

will recognise the lines-to-be-commented-out.

^FT336,495^A0B,29,33^FH\^FDEAN^FS^FX
^BY3,2,42^FT384,492^BEB,,Y,N
^FD789690466123^FS
^XA
^MMT
^LL0531
^PW1280
^LS0
^FT81,528^A0B,29,28^FH\^FDTEXT^FS               
^PQ1,0,1,Y^XZ

would ignore them, as data between ^XZ and ^XA is disregarded.

Behre answered 17/10, 2014 at 2:38 Comment(0)
F
2

I build the line to a string variable in code and put my comments in the concatenation - then send that whole string to the printer the comments will stay behind.

 StringBuilder sb = New Stringbuilder("");
 sb.append("^XA");
 sb.appendLine("^MMT");
 sb.appendLine("^LL0531");
// sb.append("this line will be commented out");
// sb.append("this line will be commented out");
// sb.append("this line will be commented out");
 sb.appendLine("^PQD,0,1,Y^XZ");

string s = sb.toString();

Something like that. You might use an 'if-else' statement instead of comments to determine if it stays in the string.

Fatima answered 16/10, 2014 at 21:24 Comment(0)
U
2

@Mangoo

The short answer is "Can't be done."

The comment-indicator is ^FX after which characters are ignored - but end-of-comment is any ^ or ~ command which makes ^FX next to useless.

Not necessarily. I found ^FX to be very useful when commenting out variables to put in test information. In this case, it is actually useful to have end-of-comment triggered by any ^ or ~ command.

With variables as field data.

^XA^PQ1
^FO12,15^A0N,36,33^FDTitle^FS
^FO210,15^A0N,36,33,^FDInfo^FS
^FO750,15^A0N,165,150^FD|Variable.Number|^FS
^FO90,60^BY4,3.0^BCN,90,N,N,Y,N^FD|Variable.Number|^FS
^XZ

With test info and variables commented out.

^XA^PQ1
^FO12,15^A0N,36,33^FDTitle^FS
^FO210,15^A0N,36,33,^FDInfo^FS
^FO750,15^A0N,165,150^FDTestNumber^FX|Variable.Number|^FS
^FO90,60^BY4,3.0^BCN,90,N,N,Y,N^FDTestNumber^FX|Variable.Number|^FS
^XZ

This makes it possible to use test information while adjusting the format and not losing the original variable names. You can also use this to make informational comments like this:

^FX This is a test label.

^XA^PQ1

^FX This is the title.
^FO12,15^A0N,36,33^FDTitle^FS

^FX This is the info.
^FO210,15^A0N,36,33,^FDInfo^FS

^FX This is the number.
^FO750,15^A0N,165,150^FD|Variable.Number|^FS

^FX This is the barcode.
^FO90,60^BY4,3.0^BCN,90,N,N,Y,N^FD|Variable.Number|^FS

^XZ
Untouched answered 15/5, 2019 at 16:51 Comment(0)
P
1

One way is to not send the command lines related to the fields you do not want to print. For the example you provided, just eliminate (do not send) the three lines starting with //.

Potheen answered 16/10, 2014 at 15:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.