3

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?

1
  • Well, I solved it by designing a compiler that supports dependent types and compiles to ZPL: github.com/capybara-language Commented Oct 13, 2015 at 11:53

3 Answers 3

3

Here is a way to do what you are looking for. Store a format with a variable. ^FN11 is the variable in the stored format. I'm storing the format on the internal flash (E:) I've named the stored format STORE.ZPL

^XA
^DFE:STORE.ZPL^FS
^FO,20,10^ADN,40,25^FH\^FN11^^FS
^XZ

I then recall the format and set the variable

^XA
^XFE:STORE.ZPL^FS
^FN11Hello World^FS
^XZ
Sign up to request clarification or add additional context in comments.

Comments

0

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")

2 Comments

ZPL is defined by its oficial documentation as a programming language and by any official document. A programming language doens't need to be turing complete to be a PL. ;)
I'm using purely ZPL. I created an IDE to develop in it and I aim to let it available on Github, but I was just searching a way to do it in pure ZPL code, no Java, C#, Scheme, Clojure and derivates. That is a pitty I can't.
0

I created a type of mark-variables, for example:

^FO 465,125
^AR
^FD.DATE.
^FS
^FO 465,280
^AR
^FD.TIME.
^FS
^FO 523,530
^AQ

Variables marks are *.DATE.* and *.TIME.*.

Then I use a Replace string method; for example, on C# :

myLabelcodeString.Replace(".DATE.,DateTime.Now.toString("dd/MM/yy")).REplace(".TIME.",DateTime.Now("hh:mm:ss tt");

and send myLabelcodeString to the printer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.