Private Sub Command1_Click()
PrintBarCode "d", 1, 1, "s"
End Sub
Public Sub PrintBarCode(TransNo As String, LineNo As Long, QtyStored As Long, SerialNo As String)
'Note: No spaces is allowed in the double-qoute of barcode printing syntax
'BarCode Printer Model : B-572-QP (Toshiba Tec)
Dim ESC: Dim LF: Dim NUL
ESC = Chr$(&H1B): LF = Chr$(&HA): NUL = Chr$(&H0)
Open "LPT1" For Output As #1
'Set initial setting
Print #1, ESC; "AY;+00,0"; LF; NUL;
Print #1, ESC; "D0980,1280,0940"; LF; NUL;
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
‘ 从画笔的当前位置到(x,y)画一条线
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
‘ 在(x,y)处输出一个字符串
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
‘ MoveToEx() 函数需要的参数
Private Type POINTAPI
xp As Long
yp As Long
End Type
Dim papi As POINTAPI
画线操作为(原来的Printer.Line函数):
MoveToEx PrintDC, x + k, y, papi
LineTo PrintDC, x + k, y + intHeight + 1
打印字符为(原来的Printer.Print函数):
TextOut PrintDC, x, y + intHeight, Mid(strBC, i + 1, 1), 1