Cara Membuat Barcode atau Mencetak Barcode dengan VB6 atau Visual Basic 6
yang terdiri dari barcode tunggal ataupun barcode kelompokDownload Visual Basic 6 atau VB6 dibawah ini :
Download Visual Basic 6.0 Enterprise Edition Service Pakc 6 (SP6)
Download Visual Basic 6.0 SP6
Download Visual Basic 6.0 Portable
Ada 2 mode pencetakan yang akan saya share disini :
1. Cetak barcode tunggal, sesuai namanya kita akan mencetak 1 kode barcode dengan posisi yang bisa kita atur sendiri.
2. Cetak barcode kelompok, mencetak beberapa kode barcode sekaligus
Oke langsung saja kita akan buat rancangan tampilannya seperti berikut :
Adapun kode pencetakannya adalah sebagai berikut :
Private Sub cmdCetak_Click()
Dim batasKiri As Single
Dim batasAtas As Single
Dim posisi As Integer
If MsgBox(
"Apakah proses pencetakan kode barcode ingin dilanjutkan ?"
, vbExclamation + vbYesNo,
"Konfirmasi"
) = vbYes Then
Screen.MousePointer = vbHourglass
DoEvents
Printer.PSet (
0
,
0
), vbWhite
Printer.ScaleMode = vbPixels
batasKiri =
0
batasAtas =
2.5
posisi =
0
Do While posisi <
30
If Check
1
(posisi).Value = Checked Then
If posisi >=
0
And posisi <=
5
Then
batasKiri =
0
ElseIf posisi >=
6
And posisi <=
11
Then
batasKiri =
4
ElseIf posisi >=
12
And posisi <=
17
Then
batasKiri =
8
ElseIf posisi >=
18
And posisi <=
23
Then
batasKiri =
12
Else
batasKiri =
16
End If
Select Case posisi
Case
0
,
6
,
12
,
18
,
24
batasAtas =
0.5
Case
1
,
7
,
13
,
19
,
25
batasAtas =
3.2
Case
2
,
8
,
14
,
20
,
26
batasAtas =
5.8
Case
3
,
9
,
15
,
21
,
27
batasAtas =
8.4
Case
4
,
10
,
16
,
22
,
28
batasAtas =
11.2
Case
5
,
11
,
17
,
23
,
29
batasAtas =
13.9
End Select
TBarCode
51
.Text = txtKodeBarcode.Text
TBarCode
51
.BackStyle = BKS_Transparent
TBarCode
51
.BCDraw Printer.hDC, Printer.ScaleX(batasKiri, vbCentimeters), Printer.ScaleY(batasAtas, vbCentimeters), Printer.ScaleX(
3
, vbCentimeters), Printer.ScaleY(
1.5
, vbCentimeters)
End If
posisi = posisi +
1
Loop
Printer.EndDoc
Screen.MousePointer = vbDefault
End If
End Sub
dan terakhir kode untuk mencetak barcode kelompok :
Private Sub cmdCetak_Click()
Dim x As Long
Dim y As Long
Dim Index As Integer
Dim sgLeft
1
As Single
Dim sgleft
2
As Single
Dim sgTop As Single
Dim fExit As Boolean
If MsgBox(
"Apakah proses pencetakan kode barcode ingin dilanjutkan ?"
, vbExclamation + vbYesNo,
"Konfirmasi"
) = vbYes Then
Screen.MousePointer = vbHourglass
DoEvents
Printer.PSet (
0
,
0
), vbWhite
Printer.ScaleMode = vbPixels
sgTop = Printer.ScaleY(
2.5
, vbCentimeters)
sgLeft
1
= Printer.ScaleX(
1
, vbCentimeters)
While fExit = False
x =
1
While fExit = False And x <=
3
y =
1
While fExit = False And y <=
4
'
top
margin
If y >
1
Then
sgTop = sgTop + Printer.ScaleY(
3.5
, vbCentimeters)
Else
sgTop = Printer.ScaleY(
2.5
, vbCentimeters)
End If
'
left
margin
If x =
1
Then
sgleft
2
= Printer.ScaleX(
1
, vbCentimeters)
ElseIf x =
2
Then
sgleft
2
= sgLeft
1
+ Printer.ScaleX(
6.79
, vbCentimeters)
Else
sgleft
2
= sgLeft
1
+ Printer.ScaleX(
6.64
, vbCentimeters)
End If
If Not ((Index +
1
) > lstDaftarBarcode.ListCount) Then
TBarCode
51
.Text = lstDaftarBarcode.List(Index)
TBarCode
51
.BackStyle = BKS_Transparent
TBarCode
51
.BCDraw Printer.hDC, sgleft
2
, sgTop, Printer.ScaleX(
4.4
, vbCentimeters), Printer.ScaleY(
1
, vbCentimeters)
End If
If (Index +
1
) > lstDaftarBarcode.ListCount Then
fExit = True
Else
Index = Index +
1
End If
y = y +
1
Wend
sgLeft
1
= sgleft
2
x = x +
1
Wend
If Not fExit Then
Printer.NewPage
sgTop = Printer.ScaleY(
2
, vbCentimeters)
sgLeft
1
= Printer.ScaleX(
1.5
, vbCentimeters)
End If
Wend
Printer.EndDoc
Screen.MousePointer = vbDefault
End If
End Sub
Download Sample Barcode
Thank's for reading the articelCara Membuat Barcode atau Mencetak Barcode dengan VB6 (Visual Basic 6) .If You want to copy paste your website please tag my link Cara Membuat Barcode atau Mencetak Barcode dengan VB6 (Visual Basic 6) Intro My Website.
0 comments:
Post a Comment