Tutorial Belajar VB.Net Khusus pemula : cara membuat Barcode menggunakan Vb.NET, aplikasi barcode sederhana menggunakan vb.net EAN 8 dan EAN 13, tutorial lengkap vb.net di sector code
Cara membuat aplikasi sederhana Barcode VB.NET - dengan bahasa pemrograman Vb.Net kita juga bisa membuat aplikasi untuk mencetak Barcode yang biasanya digunakan dalam apikasi inventory penjualan misalnya. Tutorial Sector Code sebelumnya sudah pernah membahas tentang cara pembuatan Barcode menggunakan bahasa pemrograman PHP, silahkan baca Cara membuat Barcode menggunakan PHP, SImak terus ya cara pembuatan aplikasi Barcode dengan VB.NET ini, berikut penampakan aplikasi barcode sederhana :
Penjelasan :
Component dalam pembuatan aplikasi diatas adalah : GroupBox, PictureBox, Button, dan TextBox serta label,
Membuat Functions :
Apliaksi Barcode VB.NET
Langsung saja pembuatannya, silahkan buka visual studio 2010, 2012 atau 2013 dan 2015 kamu dan buatlah project baru dengan nama "AplikasiBarcode". serta desainlah tampilan aplikasinya seperti tampilan dibawah ini :Penjelasan :
Component dalam pembuatan aplikasi diatas adalah : GroupBox, PictureBox, Button, dan TextBox serta label,
Membuat Functions Barcode VB.NET
buatlah sebuah modeule baru dengan nama "MdlBarcode.Vb" dan ikuti langkahberikut.Membuat Functions :
Private Function Barcode1(ByVal _ strBarcode As String) As String Dim _iNt As Integer Dim _StrBil As String Dim _StrEx As String Dim _StrCode As String strBarcode = Trim(strBarcode) _StrBil = strBarcode If (_StrBil.Length <> 13) And _ (_StrBil.Length <> 8) Then Err.Raise(5, "EAN2Bin", "Invalid EAN Code") End If For _iNt = 0 To strBarcode.Length - 1 Select Case (_StrBil.Chars(_iNt).ToString) Case Is < "0", Is > "9" Err.Raise(5, "EAN2Bin", _ "Invalid char on EAN Code") End Select Next If (_StrBil.Length = 13) Then _StrBil = Mid(_StrBil, 2) Select Case CInt(Left(strBarcode, 1)) Case 0 _StrCode = "000000" Case 1 _StrCode = "001011" Case 2 _StrCode = "001101" Case 3 _StrCode = "001110" Case 4 _StrCode = "010011" Case 5 _StrCode = "011001" Case 6 _StrCode = "011100" Case 7 _StrCode = "010101" Case 8 _StrCode = "010110" Case 9 _StrCode = "011010" End Select Else _StrCode = "0000" End If _StrEx = "000101" For _iNt = 1 To Len(_StrBil) \ 2 Select Case CInt(Mid(_StrBil, _iNt, 1)) Case 0 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0001101", "0100111") Case 1 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0011001", "0110011") Case 2 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0010011", "0011011") Case 3 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0111101", "0100001") Case 4 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0100011", "0011101") Case 5 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0110001", "0111001") Case 6 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0101111", "0000101") Case 7 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0111011", "0010001") Case 8 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0110111", "0001001") Case 9 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0001011", "0010111") End Select Next _iNt _StrEx &= "01010" For _iNt = Len(_StrBil) \ 2 + 1 To Len(_StrBil) Select Case CInt(Mid(_StrBil, _iNt, 1)) Case 0 _StrEx &= "1110010" Case 1 _StrEx &= "1100110" Case 2 _StrEx &= "1101100" Case 3 _StrEx &= "1000010" Case 4 _StrEx &= "1011100" Case 5 _StrEx &= "1001110" Case 6 _StrEx &= "1010000" Case 7 _StrEx &= "1000100" Case 8 _StrEx &= "1001000" Case 9 _StrEx &= "1110100" End Select Next _iNt _StrEx &= "101000" Barcode1 = _StrEx End FunctionBerikut Sub COde untuk menampilkan barcode :
Public Sub PrintBarcode2(ByVal _ _StrbarCode2 As String, _ ByVal Gambar As PictureBox, _ Optional ByVal _x1 As Single = (-1), _ Optional ByVal _y1 As Single = (-1), _ Optional ByVal _x2 As Single = (-1), _ Optional ByVal _y2 As Single = (-1), _ Optional ByVal _f As Font = Nothing) Dim _a As Single Dim _posX As Single Dim _posY As Single Dim _sX As Single Dim _StrCode As String Dim _StrFormat As New StringFormat() _StrCode = Barcode1(_StrbarCode2) If (_f Is Nothing) Then _f = New Font("Courier New", 10) End If If _x1 = (-1) Then _x1 = 0 If _y1 = (-1) Then _y1 = 0 If _x2 = (-1) Then _x2 = Gambar.Width If _y2 = (-1) Then _y2 = Gambar.Height _posX = _x1 _posY = _y2 - CSng(1.5 * _f.Height) Gambar.CreateGraphics.FillRectangle(New _ System.Drawing.SolidBrush(Gambar.BackColor), _ _x1, _y1, _x2 - _x1, _y2 - _y1) _sX = (_x2 - _x1) / _StrCode.Length For _a = 1 To Len(_StrCode) If Mid(_StrCode, _a, 1) = "1" Then Gambar.CreateGraphics.FillRectangle(New _ System.Drawing.SolidBrush(Gambar.ForeColor), _ _posX, _y1, _sX, _posY) End If _posX = _x1 + (_a * _sX) Next _a _StrFormat.Alignment = StringAlignment.Center _StrFormat.FormatFlags = StringFormatFlags.NoWrap Gambar.CreateGraphics.DrawString( _ _StrbarCode2, _f, New System.Drawing.SolidBrush(Gambar.ForeColor), _ CSng((_x2 - _x1) / 2), CSng(_y2 - _f.Height), _StrFormat) End SubUntuk code Module Barcode selengkapnya :
Option Explicit On Imports System.Drawing Module BarCodeFunctions Private Function Barcode1(ByVal _ strBarcode As String) As String Dim _iNt As Integer Dim _StrBil As String Dim _StrEx As String Dim _StrCode As String strBarcode = Trim(strBarcode) _StrBil = strBarcode If (_StrBil.Length <> 13) And _ (_StrBil.Length <> 8) Then Err.Raise(5, "EAN2Bin", "Invalid EAN Code") End If For _iNt = 0 To strBarcode.Length - 1 Select Case (_StrBil.Chars(_iNt).ToString) Case Is < "0", Is > "9" Err.Raise(5, "EAN2Bin", _ "Invalid char on EAN Code") End Select Next If (_StrBil.Length = 13) Then _StrBil = Mid(_StrBil, 2) Select Case CInt(Left(strBarcode, 1)) Case 0 _StrCode = "000000" Case 1 _StrCode = "001011" Case 2 _StrCode = "001101" Case 3 _StrCode = "001110" Case 4 _StrCode = "010011" Case 5 _StrCode = "011001" Case 6 _StrCode = "011100" Case 7 _StrCode = "010101" Case 8 _StrCode = "010110" Case 9 _StrCode = "011010" End Select Else _StrCode = "0000" End If _StrEx = "000101" For _iNt = 1 To Len(_StrBil) \ 2 Select Case CInt(Mid(_StrBil, _iNt, 1)) Case 0 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0001101", "0100111") Case 1 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0011001", "0110011") Case 2 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0010011", "0011011") Case 3 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0111101", "0100001") Case 4 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0100011", "0011101") Case 5 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0110001", "0111001") Case 6 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0101111", "0000101") Case 7 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0111011", "0010001") Case 8 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0110111", "0001001") Case 9 _StrEx &= IIf(Mid(_StrCode, _iNt, 1) = _ "0", "0001011", "0010111") End Select Next _iNt _StrEx &= "01010" For _iNt = Len(_StrBil) \ 2 + 1 To Len(_StrBil) Select Case CInt(Mid(_StrBil, _iNt, 1)) Case 0 _StrEx &= "1110010" Case 1 _StrEx &= "1100110" Case 2 _StrEx &= "1101100" Case 3 _StrEx &= "1000010" Case 4 _StrEx &= "1011100" Case 5 _StrEx &= "1001110" Case 6 _StrEx &= "1010000" Case 7 _StrEx &= "1000100" Case 8 _StrEx &= "1001000" Case 9 _StrEx &= "1110100" End Select Next _iNt _StrEx &= "101000" Barcode1 = _StrEx End Function Public Sub PrintBarcode2(ByVal _ _StrbarCode2 As String, _ ByVal Gambar As PictureBox, _ Optional ByVal _x1 As Single = (-1), _ Optional ByVal _y1 As Single = (-1), _ Optional ByVal _x2 As Single = (-1), _ Optional ByVal _y2 As Single = (-1), _ Optional ByVal _f As Font = Nothing) Dim _a As Single Dim _posX As Single Dim _posY As Single Dim _sX As Single Dim _StrCode As String Dim _StrFormat As New StringFormat() _StrCode = Barcode1(_StrbarCode2) If (_f Is Nothing) Then _f = New Font("Courier New", 10) End If If _x1 = (-1) Then _x1 = 0 If _y1 = (-1) Then _y1 = 0 If _x2 = (-1) Then _x2 = Gambar.Width If _y2 = (-1) Then _y2 = Gambar.Height _posX = _x1 _posY = _y2 - CSng(1.5 * _f.Height) Gambar.CreateGraphics.FillRectangle(New _ System.Drawing.SolidBrush(Gambar.BackColor), _ _x1, _y1, _x2 - _x1, _y2 - _y1) _sX = (_x2 - _x1) / _StrCode.Length For _a = 1 To Len(_StrCode) If Mid(_StrCode, _a, 1) = "1" Then Gambar.CreateGraphics.FillRectangle(New _ System.Drawing.SolidBrush(Gambar.ForeColor), _ _posX, _y1, _sX, _posY) End If _posX = _x1 + (_a * _sX) Next _a _StrFormat.Alignment = StringAlignment.Center _StrFormat.FormatFlags = StringFormatFlags.NoWrap Gambar.CreateGraphics.DrawString( _ _StrbarCode2, _f, New System.Drawing.SolidBrush(Gambar.ForeColor), _ CSng((_x2 - _x1) / 2), CSng(_y2 - _f.Height), _StrFormat) End Sub End ModuleSelanjutnya pada button Draw di Form Utama tuliskan code berikut untuk memanggil Functions Barcode :
Private Sub Button1_Click(ByVal sender _ As System.Object, ByVal e As _ System.EventArgs) Handles Button1.Click Try Call PrintBarcode2(Me.TextBox1.Text, _ Me.PictureBox1, 10, 10, _ Me.PictureBox1.Width - 20, _ Me.PictureBox1.Height - 20) Catch MsgBox(Err.Description, _ MsgBoxStyle.Exclamation, _ Application.ProductName) End Try End SubSilahkan bertanya seputar cara pembuatan aplikasi Barcode ini di kotak komentar, dan jangan lupa dishare jika bermanfaat. terima kasih ;)
COMMENTS