How to manually define a variable in Zebra Programming Language? (ZPL)

Marcelo Camargo picture Marcelo Camargo · Aug 29, 2014 · Viewed 10.6k times · Source

I'm programming in ZPL and I need to define a variable manually. A simple Hello World Example:

^XA
^FO,20,10^ADN,40,25^FDHello World^FS
^XZ

I want to be able to:

SET $HW$ = Hello World
^XA
^FO,20,10^ADN,40,25^FD$HW$^FS
^XZ

I read the Zebra documentation and it talks only about its use in ZebraDesigner Pro, but I must define it with code, not with graphical mode. And the variables like $CODEDATA$, SVERSION$ are not working automatically here. Then, how can I define a variable in ZPL?

Answer

mcdikki picture mcdikki · Aug 29, 2014

ZPL isn't a programming language, it's a printer language.
As I know, ZPL does not support variables. Your program should do this by building a correct ZPL code.

Building a program that does a simple substitution of a fixed string inside a text should do the trick very easy in nearly every programming language.

Thats what the designstudio is doing. It will replace the variable with the actual string and send it to the printer.

So just do something like:
Template:

template="^XA  
   ^FO,20,10^ADN,40,25^FD$HW$^FS
   ^XZ"

and then set the content:

printercommand = template.replace("$HW$", "Hello World")