CARA MEMBUAT LABEL BARCODE DENGAN EXCEL

Barcode adalah pola bar vertikal dan horisontal yang digunakan untuk mengidentifikasi produk atau komponen elektronik. Barcode membantu mengurangi kesalahan dalam memasukkan data, dan meningkatkan efisiensi dalam pengarsipan. Beberapa aplikasi yang sering menggunakan barcode adalah toko retail dan perusahaan logistik. Dalam artikel ini, kita akan membahas cara membuat barcode menggunakan Microsoft Excel dan Visual Basic.

Cara Membuat Barcode di Microsoft Excel

Microsoft Excel memiliki fitur untuk membuat barcode. Dalam tutorial ini, kita akan menggunakan font yang disebut Code 128. Code 128 adalah jenis font yang paling umum digunakan untuk barcode. Font ini mengubah teks yang Anda ketikkan menjadi pola bar. Berikut langkah-langkahnya:

  1. Buka Excel dan buatlah baris baru untuk kode barcode.
  2. Pilih baris yang baru saja Anda buat.
  3. Di bagian atas Excel, pilih “Home” kemudian tekan “Font”. Pilih jenis huruf “Code 128”.
  4. Tulis teks Anda di dalam sel, dan Excel akan mengubah teks menjadi simbol barcode.

Cara Membuat Barcode di Visual Basic

Jika Anda ingin membuat barcode dalam program Visual Basic, Anda dapat menggunakan fitur Microsoft VB 6.0. Fitur ini dapat membuat kode barcode dalam pola bar. Berikut adalah langkah-langkah yang dapat Anda gunakan:

  1. Buatlah proyek baru pada Visual Basic.
  2. Pilih “Project” kemudian “Add Module”.
  3. Gunakan kode berikut ini untuk menambahkan kelas module yang diperlukan untuk membuat barcode:
  4. Public Function BarCode128(ByVal Code As String) As StdPicture
    Dim f As Integer, r As Integer, s As String * 2, _
      BarW As Integer, BarS As Integer, _
      C As String * 1, CLeft As String * 1, _
      CRight As String * 1, FontHeight As Integer, _
      PictWidth As Integer, PictHeight As Integer
    Dim BarTTable(103, 6) As String, BarSTable(106, 6) As String
    Dim CheckSum As Integer, BarCode As String
    Dim StartChar As String * 1, StopChar As String * 1
    Dim Bitmap As Bitmap, g As Graphics, p As Point
    BarW = 1 'bar width (note that narrow bars are twice as wide as spaces)
    BarS = 2 'bar separation
    '128-B barcode encoding
    BarTTable(0, 0) = "212222"; BarTTable(1, 0) = "222122"
    BarTTable(2, 0) = "222221"; BarTTable(3, 0) = "121223"
    BarTTable(4, 0) = "121322"; BarTTable(5, 0) = "131222"
    BarTTable(6, 0) = "122213"; BarTTable(7, 0) = "122312"
    BarTTable(8, 0) = "132212"; BarTTable(9, 0) = "221213"
    BarTTable(10, 0) = "221312"; BarTTable(11, 0) = "231212"
    BarTTable(12, 0) = "112232"; BarTTable(13, 0) = "122132"
    BarTTable(14, 0) = "122231"; BarTTable(15, 0) = "113222"
    BarTTable(16, 0) = "123122"; BarTTable(17, 0) = "123221"
    BarTTable(18, 0) = "223211"; BarTTable(19, 0) = "221132"
    BarTTable(20, 0) = "221231"; BarTTable(21, 0) = "213212"
    BarTTable(22, 0) = "223112"; BarTTable(23, 0) = "312131"
    BarTTable(24, 0) = "311222"; BarTTable(25, 0) = "321122"
    BarTTable(26, 0) = "321221"; BarTTable(27, 0) = "312212"
    BarTTable(28, 0) = "322112"; BarTTable(29, 0) = "322211"
    BarTTable(30, 0) = "212123"; BarTTable(31, 0) = "212321"
    BarTTable(32, 0) = "232121"; BarTTable(33, 0) = "111323"
    BarTTable(34, 0) = "131123"; BarTTable(35, 0) = "131321"
    BarTTable(36, 0) = "112313"; BarTTable(37, 0) = "132113"
    BarTTable(38, 0) = "132311"; BarTTable(39, 0) = "211313"
    BarTTable(40, 0) = "231113"; BarTTable(41, 0) = "231311"
    BarTTable(42, 0) = "112133"; BarTTable(43, 0) = "112331"
    BarTTable(44, 0) = "132131"; BarTTable(45, 0) = "113123"
    BarTTable(46, 0) = "113321"; BarTTable(47, 0) = "133121"
    BarTTable(48, 0) = "313121"; BarTTable(49, 0) = "211331"
    BarTTable(50, 0) = "231131"; BarTTable(51, 0) = "213113"
    BarTTable(52, 0) = "213311"; BarTTable(53, 0) = "213131"
    BarTTable(54, 0) = "311123"; BarTTable(55, 0) = "311321"
    BarTTable(56, 0) = "331121"; BarTTable(57, 0) = "312113"
    BarTTable(58, 0) = "312311"; BarTTable(59, 0) = "332111"
    BarTTable(60, 0) = "314111"; BarTTable(61, 0) = "221411"
    BarTTable(62, 0) = "431111"; BarTTable(63, 0) = "111224"
    BarTTable(64, 0) = "111422"; BarTTable(65, 0) = "121124"
    BarTTable(66, 0) = "121421"; BarTTable(67, 0) = "141122"
    BarTTable(68, 0) = "141221"; BarTTable(69, 0) = "112214"
    BarTTable(70, 0) = "112412"; BarTTable(71, 0) = "122114"
    BarTTable(72, 0) = "122411"; BarTTable(73, 0) = "142112"
    BarTTable(74, 0) = "142211"; BarTTable(75, 0) = "241211"
    BarTTable(76, 0) = "221114"; BarTTable(77, 0) = "413111"
    BarTTable(78, 0) = "241112"; BarTTable(79, 0) = "134111"
    BarTTable(80, 0) = "111242"; BarTTable(81, 0) = "121142"
    BarTTable(82, 0) = "121241"; BarTTable(83, 0) = "114212"
    BarTTable(84, 0) = "124112"; BarTTable(85, 0) = "124211"
    BarTTable(86, 0) = "411212"; BarTTable(87, 0) = "421112"
    BarTTable(88, 0) = "421211"; BarTTable(89, 0) = "212141"
    BarTTable(90, 0) = "214121"; BarTTable(91, 0) = "412121"
    BarTTable(92, 0) = "111143"; BarTTable(93, 0) = "111341"
    BarTTable(94, 0) = "131141"; BarTTable(95, 0) = "114113"
    BarTTable(96, 0) = "114311"; BarTTable(97, 0) = "411113"
    BarTTable(98, 0) = "411311"; BarTTable(99, 0) = "113141"
    BarTTable(100, 0) = "114131"; BarTTable(101, 0) = "311141"
    BarTTable(102, 0) = "411131"; BarTTable(103, 0) = "211412"
    'Create start character
    StartChar = Chr(204) 'Code B Start
    StartChar = Mid(StartChar, 2, 1) & Chr(CInt(Mid(StartChar, 1, 1)) + 104)
    BarCode = StartChar 'add start
    For f = 1 To Len(Code)
      C = Mid(Code, f, 1)
      CLeft = Mid(Code, f + 1, 1)
      CRight = Mid(Code, f - 1, 1)
      If C = ")" And IsNumeric(CLeft) And Not IsNumeric(CRight) Then C = Char(194) 'FNC1 character
      'Find the bar and space widths for the character
      For r = 0 To 105
        If BarTTable(r, 0) = "" Then
          'character not valid
          Err.Raise vbObjectError, "BarCode128 Invalid Character", "Character not supported by 128-B Barcode"
        ElseIf BarTTable(r, 0) = Mid(Code, f, 1) Then
          'character found
          BarCode = BarCode & BarTTable(r, 1)
          BarCode = BarCode & BarTTable(r, 2)
          BarCode = BarCode & BarTTable(r, 3)
          BarCode = BarCode & BarTTable(r, 4)
          BarCode = BarCode & BarTTable(r, 5)
          BarCode = BarCode & BarTTable(r, 6)
          BarCode = BarCode & "0" 'space
          Exit For
        End If
      Next
    Next
    BarCode = Mid(BarCode, 1, Len(BarCode) - 1) 'remove trailing space
    'Calculate Check Character
    CheckSum = 103
    For f = 1 To Len(Code)
      C = Mid(Code, f, 1)
      For r = 0 To 105
        If BarTTable(r, 0) = C Then CheckSum = CheckSum + (r * f)
      Next
    Next
    CheckSum = CheckSum Mod 103
    'Find check character
    For r = 0 To 105
      If BarTTable(r, 0) = Chr(CheckSum) Then
        BarCode = BarCode & BarTTable(r, 1)
        BarCode = BarCode & BarTTable(r, 2)
        BarCode = BarCode & BarTTable(r, 3)
        BarCode = BarCode & BarTTable(r, 4)
        BarCode = BarCode & BarTTable(r, 5)
        BarCode = BarCode & BarTTable(r, 6)
        Exit For
      End If
    Next
    'Create stop character
    StopChar = Chr(206) 'Stop Character
    StopChar = Mid(StopChar, 2, 1) & Chr(CInt(Mid(StopChar, 1, 1)) + 104)
    BarCode = BarCode & StopChar 'add stop
    FontHeight = 23 'height for Code 128
    BarCodeWidth = (Len(BarCode) / 2) * (BarW + BarS) - BarS 'Calculate Width
    BMWidth = BarCodeWidth + 40   'add 20 pixels margin to width
    PictWidth = BMWidth
    PictHeight = FontHeight + 20 'add 10 pixels margin to height
    Set Bitmap = New Bitmap(PictWidth, PictHeight)
    Set g = Graphics.FromImage(Bitmap)
    g.Clear(Color.White)
    p.Y = 10   'Set Top Margin
    For f = 1 To Len(BarCode) Step 2
      s = Mid(BarCode, f, 2)
      If s = "22" Then '1 Wide Bar
        g.FillRectangle(Brushes.Black, p.X, p.Y, BarW, FontHeight)
        p.X = p.X + BarW + BarS
      ElseIf s = "12" Then  '1 Narrow Bar
        g.FillRectangle(Brushes.Black, p.X, p.Y, BarW / 2, FontHeight)
        p.X = p.X + BarW / 2 + BarS
      ElseIf s = "24" Then  '2 Wide Bar
        g.FillRectangle(Brushes.Black, p.X, p.Y, 2 * BarW, FontHeight)
        p.X = p.X + 2 * BarW + BarS
      ElseIf s = "34" Then  '3 Wide Bar
        g.FillRectangle(Brushes.Black, p.X, p.Y, 3 * BarW, FontHeight)
        p.X = p.X + 3 * BarW + BarS
      End If
    Next
    Return Bitmap
    End Function
  5. Tambahkan kode berikut ini pada event “Button_Click” untuk menampilkan barcode:
  6. Dim picBarcode As PictureBox
    Set picBarcode = New PictureBox
    With picBarcode
      .Name = "Barcode"
      .Width = 350
      .Height = 50
      .SizeMode = PictureBoxSizeMode.StretchImage
      .Image = BarCode128("123456")
      .Location = New Point(10, 10)
    End With
    Me.Controls.Add(picBarcode)
  7. Ubahlah parameter teks “123456” dengan teks yang ingin Anda ubah menjadi barcode.
  8. Jalankan program untuk melihat barcode yang dihasilkan.
Baca Juga :  Cara Membuat Program Sederhana Menggunakan Excel

FAQ

1. Apa itu barcode?

Barcode adalah pola bar vertikal dan horisontal yang digunakan untuk mengidentifikasi produk atau komponen elektronik. Barcode membantu mengurangi kesalahan dalam memasukkan data, dan meningkatkan efisiensi dalam pengarsipan. Beberapa aplikasi yang sering menggunakan barcode adalah toko retail dan perusahaan logistik.

2. Apa saja jenis font yang dapat digunakan untuk membuat barcode?

Beberapa jenis font yang sering digunakan untuk membuat barcode antara lain Code 128, Code 39, dan Interleaved 2 of 5.