ZPL Comment Line
I want to comment out lines in ZPL code like:
^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 doesn't want to print the barcode. Is it possible? or is there a better way not to print the barcode?
source to share
The short answer is "Impossible to do".
A comment indicator ^FX
after which characters are ignored - but the end of the comment any ^ or ~ command
, making it ^FX
next to useless.
Unless a block-comment command has been added, with a specific start / end-block-comment mnemonic set, then sorry — you're out of luck.
All is not entirely lost.
^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 recognize missing lines.
^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
ignores them because data between ^XZ
and is ^XA
not counted.
source to share
I am building a string into a string variable in code and putting my comments in concatenation - then sending that whole string to the printer, the comments are left 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 can use the if-else statement instead of comments to determine if it stays on the line.
source to share
@Mangoo
The short answer is "Can't be done."
The comment indicator is ^ FX, after which characters are ignored, but the end of the comment is any ^ or ~ command that makes ^ FX useless.
Not necessary. I found ^ FX very useful when commenting out variables for pasting test information. In this case, it is actually useful for the end of the comment to be 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 information and commented out variables.
^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 allows you to use test information when setting up the format and not lose 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
source to share