CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Location
    PA
    Posts
    124

    Using Text Template for Zebra ZPL in VB.Net

    I am writing a printer utility to print labels with the Zebra ZPL scripting language(??), or whatever you want to call ZPL.

    Up to now, I have created the ZPL and then embedded that into my VB.Net program (windows Touchscreen form). This works fine, until I need to make a small change to the ZPL layout. Then I have to recompile and distribute the code.

    That sucks.

    So, I am looking for a way to make a text file that I can use that will be used for the layout. I will still have to distribute the text file, but at least it will not require me to build and deploy.

    Since ALL of the active objects on the label do not change, typically only the positions, this should be relatively easy.

    Is there a best practices technique for doing this?

    I was thinking about putting in placeholders at the data element position such as follows (every numbered @vx is a placeholder):

    Code:
    ^XA~TA000~JSN^LT0^MMT^MNW^MTT^PON^PMN^LH0,0^JMA^PR4,4^MD0^JUS^LRN^CI0^XZ^XA^LL0609^PRD
    ^FO500,100^A@R,50,50,E:Koriieb_.ttf^FH^FDBox #: @v1^FS
    ^FO500,550^A@R,40,40,E:Koriieb_.ttf^FH^FDDate: @v2^FS
    ^FO450,100^A@R,40,40,E:Koriieb_.ttf^FH^FDVendor: @v3^FS
    ^FO400,100^A@R,40,40,E:Koriieb_.ttf^FH^FDPO #: @v4^FS
    ^FT350,300^A@R,60,60,E:Koriieb_.ttf^^FH\^FD@v5^FS
    ^FT300,100^A@R,40,40,E:Koriieb_.ttf^FD@v6^FS
    ^BY3,2,125^FT150,250^BCR,,N,N^FD@v5^FS
    ^FT50,100^A@R,60,60,E:Koriieb_.ttf^FH\^FDWeight: @v7 LBS^FS
    ^PQ1,0,1,Y
    ^XZ
    Does this make sense? Is there a better way to do this?
    There are 10 types of people in the world, those that understand binary and those that don't.
    Using VS 2010

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Using Text Template for Zebra ZPL in VB.Net

    ZPL = Zebra Programming Language

    What you suggest should work, personally I would use something more descriptive than V1 -V7

    I have did several programs that do use a text file for the layout and have used standins for the data portions like %PartNumber% for example.
    The program then of course replaces %PartNumber% with the actual data that goes in the part number section.

    Of course those short codes will work but may require some thinking after a short while away from the project whereas more descriptive terms will be easier to know what is going on even when the project is no longer fresh in the mind.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jul 2003
    Location
    PA
    Posts
    124

    Re: Using Text Template for Zebra ZPL in VB.Net

    Thanks for the feedback. I took your suggestion and changed the variables in the text file to be of the form %value%.

    Here is what I cam up with. I had to use the StringBuilder object to make it work, but that is a minor concession.

    To read this, the _bct values being used in substitution are part of a structure.

    Code:
    Function parse_text(_bct as bcout) As String
            Dim f As String = ""
            Dim s1 As New StringBuilder
            Dim pth As String = Directory.GetCurrentDirectory() & "\repro.txt"
            Dim readText() As String = File.ReadAllLines(pth)
            Dim s As String
            For Each s In readText
                s1.Clear()
                s1.Append(s)
                s1.Replace("%box%",      _bct.box_no.ToString())
                s1.Replace("%date%",     Date.Now.ToString("MM/dd/yyyy"))
                s1.Replace("%vendor%",   _bct.vendor.ToString())
                s1.Replace("%po%",       _bct.repro_po.ToString())
                s1.Replace("%litm%",     _bct.imlitm.ToString())
                s1.Replace("%dsc1%",     _bct.dsc1.ToString())
                s1.Replace("$weight%",   _bct.box_wt.ToString())
                s1.Replace("%qty%",      _bct.qty.ToString())
                f = f & s1.ToString()
            Next
            parse_text = f
    End Function
    Last edited by rick7423; June 16th, 2016 at 08:34 AM.
    There are 10 types of people in the world, those that understand binary and those that don't.
    Using VS 2010

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured