Jump to content
Sign in to follow this  

Template File

Recommended Posts

I have created a GUI program (to be compiled) that some of my users will be using to print par code labels. To do this, I need to create a file that contains WPL (Wasp Printer Language). Only a few small parts of this data will change depending on the options submitted, so I thought I would use a "template" text file that will be parsed, and some sort of "variable" syntax will be included so that a find & replace is performed, and the new resulting text file would have the "variables" replaced with the data to reflect what the user selected in the form.

I am picturing something akin to an HTML template file...

EXAMPLE: (This is just a demonstration. I will tackle exactly how the syntax will work before I focus too much time on the specifics of this syntax. I am going to use "$" vars, since that is easy for me to relate to and tell apart for this example.)


SIZE  $mediaWidth, $mediaHeight
KILL "*"

BARCODE $locLeft,$locRight,"$type",196,1,0,2,4,$identifier
PRINT 1,$prtCnt


$mediaWidth = 2.25

$mediaHeight = 1.25

$locLeft = 76

$locRight = 17

$type = EAN13+5

$identifier = 97816061102052500

$prtCnt = 22

(Template file is then parsed, and vars are replaced. The final version (below) is written to a temp file, where it is then sent to the printer as a raw message.

Please let me know if you need more information. I am happy to fill in the holes.


Chay D. Butler (New Leaf Distributing)


SIZE  2.25, 1.25
KILL "*"

BARCODE 76,17,"EAN13+5",196,1,0,2,4,"97816061102052500"
PRINT 1,22

Share this post

Link to post
Share on other sites

This one looks like it may be helpful: http://www.autoitscript.com/forum/index.php?showtopic=119096

I'm well versed with using Regexp and concepts like "StringReplace", but am wondering if there is a better, more official, or "correct" way to perform this action. So, if you have any thoughts, please post!


Chay Butler

New Leaf Distributing

If it's not too long, why not hard code the proposed file content into a variable within your program, with the appropriate other variables interspersed as required. You can then just write it to a file as required.

Otherwise, you could use the original template idea, 'move' it to a new name [so the original template file remains unedited] and use _ReplaceStringInFile to make the required changes.



Share this post

Link to post
Share on other sites

Just write a simple function, like this:

$sResult = _GenBarCodeWPL("2.25", "1.25", 76, 17, "EAN13+5", "97816061102052500", 22)
MsgBox(64, "Result", "$sResult = " & @CRLF & $sResult)

Func _GenBarCodeWPL($sMediaW, $sMediaH, $sLocL, $sLocR, $sType, $sID, $sPrtCnt)
    Local $sWPL = 'SIZE ' & $sMediaW & ', ' & $sMediaH & @CRLF & _
        'DENSITY  7' & @CRLF & _
        'SPEED  4' & @CRLF & _
        'DIRECTION  1' & @CRLF & _
        'KILL "*"' & @CRLF & _
        'CLS' & @CRLF & _
        'BARCODE ' & $sLocL& ',' & $sLocR & ',"' & $sType & '",196,1,0,2,4,"' & $sID & '"' & @CRLF & _
        'PRINT 1,' & $sPrtCnt & @CRLF
    Return $sWPL


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...