ZPL Example for Visual Basic

  1. Example using batch file.

Sub SAMPLE_Print()

'
'  The following will run zpl.bat.
'

Dim stAppName As String
stAppName = "c:\zpl.bat"
Call Shell(stAppName, 3)
'
' Where the contents of c:\zpl.bat would be:
' COPY ZPL.TXT LPT1
' ZPL.TXT would contain the required ZPL command code.
'

End Sub

  1. Example printing directly to the Parallel Port:

Sub SAMPLE_Print()


' Open port for printing
'
Open "LPT1:" For Output As #1
'
' Send ZPL code to port, line by line
'

Print #1, "^XA"
Print #1, "^FO100,100^A0N,50,50^FDHELLO^FS"
Print #1, "^XZ"
Close #1

End Sub

  1. Example printing directly to the appropriate COM Port:

Sub SAMPLE_Print()

'
' Set Communications Parameters on Com Port (in this case COM1).
'

MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.Handshaking = "comXonXoff"
MSComm1.PortOpen = True

'
' Send ZPL code to Port, line by line.
'

MSComm1.Output = "^XA"
MSComm1.Output = "^FO100,100^A0N,50,50^FDHELLO^FS"
MSComm1.Output = "^XZ"

End Sub

  1. Example printing directly to a driver (generic text driver).

Sub SAMPLE_Print()

Printer.Print "^XA"
Printer.Print "^FO20,20^A0N,50,50^FDHELLO^FS"
Printer.Print "^XZ"
Printer.EndDoc

End Sub

 

Additional information can be obtained on Microsoft's Tech Net