Berikut ini adalah contoh program VB6 untuk membuat print out untuk struk atau nota pos dengan menggunakan printer POS EPSON TMU220 dengan auto cutter, berikut ini adalah class clsPrintNota:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
Dim mHeader1 As String
Dim mHeader2 As String
Dim mHeader3 As String
Dim mFooter As String
Dim mTanggal As String
Dim mNomor As String
Dim mSales As String
Dim mItem() As RowField
Dim mItemCount As Integer
Dim mPrinterName As String
Dim mDiskonPersen As String
Dim mDiskonNilai As String
Dim mPPNPersen As String
Dim mPPNNilai As String
Dim mSubTotal As String
Dim mTotal As String
 
Private Type RowField
    NamaBarang As String
    Qty As String
    HargaSatuan As String
    HargaTotal As String
End Type
 
Private Sub Class_Initialize()
    mDiskonPersen = "0%"
    mDiskonNilai = "0"
 
    mPPNPersen = "0%"
    mPPNNilai = "0"
End Sub
 
Public Property Let Header1(ByVal param As String)
    mHeader1 = param
End Property
 
Public Property Let Header2(ByVal param As String)
    mHeader2 = param
End Property
 
Public Property Let Header3(ByVal param As String)
    mHeader3 = param
End Property
 
Public Property Let Footer(ByVal param As String)
    mFooter = param
End Property
 
Public Property Let Tanggal(ByVal param As String)
    mTanggal = param
End Property
 
Public Property Let Nomor(ByVal param As String)
    mNomor = param
End Property
 
Public Property Let Sales(ByVal param As String)
    mSales = param
End Property
 
Public Property Get ItemCount() As Integer
    ItemCount = mItemCount
End Property
 
Public Property Let PrinterName(param As String)
    mPrinterName = param
End Property
 
Public Sub SetDiskon(ByVal persen As String, ByVal nilai As String)
    mDiskonPersen = persen
    mDiskonNilai = nilai
End Sub
 
Public Sub SetPPN(ByVal persen As String, ByVal nilai As String)
    mPPNPersen = persen
    mPPNNilai = nilai
End Sub
 
Public Property Let SubTotal(ByVal param As String)
    mSubTotal = param
End Property
 
Public Property Let Total(ByVal param As String)
    mTotal = param
End Property
 
Public Sub AddItem(ByVal param1 As String, ByVal param2 As String, ByVal param3 As String, ByVal param4 As String)
    ReDim Preserve mItem(mItemCount)
 
    mItem(mItemCount).NamaBarang = param1
    mItem(mItemCount).Qty = param2
    mItem(mItemCount).HargaSatuan = param3
    mItem(mItemCount).HargaTotal = param4
    mItemCount = mItemCount + 1
End Sub
 
Public Sub PrintNota()
    Const PAPER_WIDTH As Integer = 40
    Const RIGHT_MARGIN As Integer = 37
    Const LEFT_MARGIN As Integer = 0
    Const CENTER_MARGIN As Integer = 20
 
    Dim GARIS1 As String
    Dim GARIS2 As String
    Dim GARIS_PLUS As String
    Dim GARIS_MINUS As String
    Dim Qty As String
    Dim i As Integer
 
    GARIS1 = String$(PAPER_WIDTH, "-")
    GARIS2 = String$(PAPER_WIDTH, "=")
    GARIS_PLUS = String$(PAPER_WIDTH - 4, "-") & " (+)"
    GARIS_MINUS = String$(PAPER_WIDTH - 4, "-") & " (-)"
 
    On Error GoTo errH
    Open mPrinterName For Output As #1
 
    'Begin print
    Print #1, Chr$(&H1B); "@";
    Print #1, Tab((PAPER_WIDTH - Len(mHeader1)) / 2); mHeader1
    Print #1, Tab((PAPER_WIDTH - Len(mHeader2)) / 2); mHeader2
    Print #1, Tab((PAPER_WIDTH - Len(mHeader3)) / 2); mHeader3
    Print #1, GARIS2
 
    Print #1, Tab(LEFT_MARGIN); "Tanggal : "; mTanggal
    Print #1, Tab(LEFT_MARGIN); "Nomor   : "; mNomor
    Print #1, Tab(LEFT_MARGIN); "Sales   : "; mSales
    Print #1, GARIS1
    For i = 0 To mItemCount - 1
        Qty = mItem(i).Qty & " x " & mItem(i).HargaSatuan
        Print #1, Tab(LEFT_MARGIN); Left$(mItem(i).NamaBarang, RIGHT_MARGIN - LEFT_MARGIN)
        Print #1, Tab(CENTER_MARGIN - (Len(Qty))  2); Qty;
        Print #1, Tab(RIGHT_MARGIN - Len(mItem(i).HargaTotal)); mItem(i).HargaTotal
    Next i
    Print #1, GARIS_PLUS
    Print #1, Tab(LEFT_MARGIN); "SUB TOTAL"; Tab(RIGHT_MARGIN - Len(mSubTotal)); mSubTotal
    Print #1, Tab(LEFT_MARGIN); "DISKON(" & mDiskonPersen & ")"; Tab(RIGHT_MARGIN - Len(mDiskonNilai)); mDiskonNilai
    Print #1, Tab(LEFT_MARGIN); "PPN(" & mPPNPersen & ")"; Tab(RIGHT_MARGIN - Len(mPPNNilai)); mPPNNilai
    Print #1, GARIS_PLUS
 
    Print #1, Tab(LEFT_MARGIN); "TOTAL"; Tab(RIGHT_MARGIN - Len(mTotal)); mTotal
    Print #1, GARIS2
    Print #1, Tab((PAPER_WIDTH - Len(mFooter)) / 2); mFooter;
    Print #1, Chr$(&HA);
    Print #1, Chr$(&H1D); "V"; Chr$(66); Chr$(0);
 
    Close #1
    Exit Sub
errH:
    'MsgBox Err.Description
    Dim jwb As Integer
    jwb = MsgBox("Printer ERROR!" & vbCrLf & "Betulkan printer, lalu klik OK", vbOKCancel, "Printer Error")
    If jwb = vbOK Then
        Resume
    End If
End Sub
Berikut adalah contoh penggunaannya:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Private Sub PrintNota()
    Dim oPrint As New clsPrintNota
 
    oPrint.PrinterName = "LPT1"
    oPrint.Header1 = "Nama perusahaan"
    oPrint.Header2 = "Alamat"
    oPrint.Header3 = "Telp"
    oPrint.Footer = ".:Terimakasih:."
 
    oPrint.Nomor = "001"
    oPrint.Tanggal = "20-01-2009"
    oPrint.Sales = "ARL"
 
    oPrint.SetDiskon "10%", "-35.000"
    oPrint.SetPPN "10%", "31.500"
    oPrint.SubTotal = "350.000"
    oPrint.Total = "346.500"
 
    oPrint.AddItem "HP Nokia 3310", "1", "150.000", "150.000"
    oPrint.AddItem "HP Nokia 3315", "1", "200.000", "200.000"
    oPrint.PrintNota
End Sub
 
Call PrintNota()

 
[My-Blogs]