Friday, 7 August 2015

VB6.0 :: membuat ID Card + Barcode dengan VB6


Setiap orang per orang atau pun instansi menginginkan setiap dana yang dikeluarkan memiliki nilai yang sangat minimal, oleh karena itu tidak jarang terjebak dengan kualitas yang tidak begitu memuaskan.
Sama halnya dengan pemilihan Kartu Karyawan banyak sekali pilihan dari yang biasa saja hingga yang sangat mewah. Pada blog ini saya hanya ingin berbagi, untuk tiap perusahaan pun dapat membuat ID Card dengan kreasi dari departemen IT nya sendiri. Berikut yang harus disediakan untuk tambahan pembuatan ID Card, selain Printer untuk mencetak dan aplikasinya
Kertas Inkjet, ketebalan atau pun merk bisa ditentukan sendiri
Plastik Laminating, dapat disesuaikan dengan kebutuhan
Pada bagian ini, saya akan berbagi tentang aplikasinya yang dibuat dengan menggunakan VB6
Berikut form yang harus disiapkan:
Keterangan Form:
ControlProperties NameProperties Caption
FrameFrame1
LabelLabel1Masukan ID
TextBoxText1
CommonDialogCmdDialog
CommandButtonCmdPrintPrint
LabelLblEmployee2Nama Karyawan
LabelLblPosition2Divisi
LabelLblNIK2NIKK
LabelLblCompanyNama Perusahaan
LabelLblAttentionPerhatian
LabelLbl1Kartu karyan ini………………….
LabelLbl2Kartu karyan ini dipelihara………………….
LabelLbl3Mentaati Peraturan ……
LabelLbl4Employee Signature
LabelLbl5HRD Anda
LabelLbl6Personalia
PictureBoxPictBack2
PictureBoxPictBar6
PictureBoxPicture4
ImagePictID2
Berikut bahasa program yang harus ada pada form (atau cukup copy seluruh):Dim sNameFile As String
Private Sub cmdPrint_Click()
cmdPrint.Visible = False
Frame1.Visible = False
Me.PrintForm
cmdPrint.Visible = True
Frame1.Visible = True
End Sub
Private Sub Text1_LostFocus()
lblNIK2.Caption = Text1.Text
With PictBar6
.ScaleMode = 3
.Height = .Height * (1.4 * 40 / .ScaleHeight)
.FontSize = 8
End With
Call DrawBarcode(Text1.Text, PictBar6)
With Me
sNameFile = Text1.Text
FileSave PictBar6
.PictBar6.Picture = LoadPicture(App.Path & “\” & Text1.Text & “.bmp”)
.PictBar6.Left = ((.PictBack2.Width – .PictBar6.Width) / 2) + 200
End With
End Sub
Sub FileSave(Picbox As PictureBox)
‘This Procedure Saves the Bars to desired Format
Dim sName, retVal, retSave
Screen.MousePointer = 11
On Error GoTo ErrHandler
If LastSave “” Then
CmdDialog.InitDir = App.Path & “\”
Else
CmdDialog.InitDir = App.Path & “\”
End If
CmdDialog.FileName = sNameFile & “.bmp”
CmdDialog.CancelError = True
CDialog.Flags = cdlOFNOverwritePrompt + cdlOFNNoReadOnlyReturn
CmdDialog.Filter = “Bitmaps (*.bmp)|*.bmp|Gif (*.gif)|*.gif|Transparent Gif (*.gif)|*.gif”
LastSave = CmdDialog.InitDir
CmdDialog.ShowSave
‘retrive the Folder Name
retSave = InStrRev(CmdDialog.FileName, “\”)
LastSave = Mid(CmdDialog.FileName, 1, retSave)
DoEvents
Picbox.Picture = Picbox.Image
CmdDialog.FilterIndex = 1
Select Case CmdDialog.FilterIndex
Case 1: ‘if BITMAP is selected
SavePicture Picbox.Picture, CmdDialog.FileName
Case 2: ‘if GIF is selected
‘Set ObjGifImg = New GIF
ObjGifImg.SaveGIF Picbox.Image, CmdDialog.FileName, Picbox.hDC, False, Picbox.Point(0, 0)
Set ObjGifImg = Nothing
Case 2: ‘if Transperent GIF is selected
‘Set ObjGifImg = New GIF
ObjGifImg.SaveGIF Picbox.Image, CmdDialog.FileName, Picbox.hDC, True, Picbox.Point(0, 0)
Set ObjGifImg = Nothing
End Select
Screen.MousePointer = 0
Exit Sub
ErrHandler:
If Err.Number = 32755 Then ‘ Handle the Cancel error
Screen.MousePointer = 0
Exit Sub
Else
If Err.Number 0 Then MsgBox “Error saving file: ” & Err.Number & ” – ” & Err.Description
Screen.MousePointer = 0
End If
End Sub
Tambahkan modul ini dengan Name: mdl39‘—————————————————————————————
‘ Fixes : The Bar39 had a small bug in printing ‘*’,
‘ which is essential for Barcode Readers.
‘—————————————————————————————
Sub DrawBarcode(ByVal bc_string As String, obj As Object)
Dim xpos!, Y1!, Y2!, dw%, Th!, tw, new_string$
If bc_string = “” Then obj.Cls: Exit Sub
‘define barcode patterns
Dim bc(90) As String
bc(1) = “1 1221″ ‘pre-amble
bc(2) = “1 1221″ ‘post-amble
bc(48) = “11 221″ ‘digits
bc(49) = “21 112″
bc(50) = “12 112″
bc(51) = “22 111″
bc(52) = “11 212″
bc(53) = “21 211″
bc(54) = “12 211″
bc(55) = “11 122″
bc(56) = “21 121″
bc(57) = “12 121″
‘capital letters
bc(65) = “211 12″ ‘A
bc(66) = “121 12″ ‘B
bc(67) = “221 11″ ‘C
bc(68) = “112 12″ ‘D
bc(69) = “212 11″ ‘E
bc(70) = “122 11″ ‘F
bc(71) = “111 22″ ‘G
bc(72) = “211 21″ ‘H
bc(73) = “121 21″ ‘I
bc(74) = “112 21″ ‘J
bc(75) = “2111 2″ ‘K
bc(76) = “1211 2″ ‘L
bc(77) = “2211 1″ ‘M
bc(78) = “1121 2″ ‘N
bc(79) = “2121 1″ ‘O
bc(80) = “1221 1″ ‘P
bc(81) = “1112 2″ ‘Q
bc(82) = “2112 1″ ‘R
bc(83) = “1212 1″ ‘S
bc(84) = “1122 1″ ‘T
bc(85) = “2 1112″ ‘U
bc(86) = “1 2112″ ‘V
bc(87) = “2 2111″ ‘W
bc(88) = “1 1212″ ‘X
bc(89) = “2 1211″ ‘Y
bc(90) = “1 2211″ ‘Z
‘Misc
bc(32) = “1 2121″ ‘space
bc(35) = “” ‘# cannot do!
bc(36) = “1 1 1 11″ ‘$
bc(37) = “11 1 1 1″ ‘%
bc(43) = “1 11 1 1″ ‘+
bc(45) = “1 1122″ ‘-
bc(47) = “1 1 11 1″ ‘/
bc(46) = “2 1121″ ‘.
bc(64) = “” ‘@ cannot do!
‘A Fix made by changing 65 to 42.
bc(42) = “1 1221″ ‘*
bc_string = UCase(bc_string)
‘dimensions
obj.ScaleMode = 3 ‘pixels
obj.Cls
obj.Picture = Nothing
dw = CInt(obj.ScaleHeight / 40) ‘space between bars
If dw 90 Then C = 0
bc_pattern$ = bc(C)
‘draw each bar
For i = 1 To Len(bc_pattern$)
Select Case Mid$(bc_pattern$, i, 1)
Case ” ”
‘space
obj.Line (xpos, Y1)-(xpos + 1 * dw, Y2), &HFFFFFF, BF
xpos = xpos + dw
Case “1”
‘space
obj.Line (xpos, Y1)-(xpos + 1 * dw, Y2), &HFFFFFF, BF
xpos = xpos + dw
‘line
obj.Line (xpos, Y1)-(xpos + 1 * dw, Y2), &H0&, BF
xpos = xpos + dw
Case “2”
‘space
obj.Line (xpos, Y1)-(xpos + 1 * dw, Y2), &HFFFFFF, BF
xpos = xpos + dw
‘wide line
obj.Line (xpos, Y1)-(xpos + 2 * dw, Y2), &H0&, BF
xpos = xpos + 2 * dw
End Select
Next
Next
‘1 more space
obj.Line (xpos, Y1)-(xpos + 1 * dw, Y2), &HFFFFFF, BF
xpos = xpos + dw
‘final size and text
obj.Width = (xpos + dw) * obj.Width / obj.ScaleWidth
obj.CurrentX = (obj.ScaleWidth – tw) / 2
obj.CurrentY = Y2 + 0.25 * Th
obj.Print bc_string
End Sub

Silakan unduh di sini
 

No comments:

Post a Comment