Äàííûé VBA-ìàêðîñ ïðåäíàçíà÷åí äëÿ ïîäãîòîâêè êîäîâûõ êîìáèíàöèé êîäà EAN13 äëÿ èõ ïîñëåäóþùåé ïå÷àòè øðèôòîì EanBwrP36Tt Normal.Ttf. Ìàêðîñ íóæíî ïîìåñòèòü â øàáëîí îò÷åòà «Áàçà MS Access» (ñì. 14.3), èç êîòîðîãî áóäóò ïå÷àòàòüñÿ äîêóìåíû, êîäèðîâàííûå äàííûì êîäîì.

 

Public Sub EAN13CODE(Code, BarCode)

'

'Ï/ïðîãðàììà êîäèðîâàíèÿ êîäîì EAN13

'

Dim R As Double

Dim A, B, C, ISP

A = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")

B = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")

C = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")

ISP = Array(Array("A", "A", "A", "A", "A", "A"), _

            Array("A", "A", "B", "A", "B", "B"), _

            Array("A", "A", "B", "B", "A", "B"), _

            Array("A", "A", "B", "B", "B", "A"), _

            Array("A", "B", "A", "A", "B", "B"), _

            Array("A", "B", "B", "A", "A", "B"), _

            Array("A", "B", "B", "B", "A", "A"), _

            Array("A", "B", "A", "B", "A", "B"), _

            Array("A", "B", "A", "B", "B", "A"), _

            Array("A", "B", "B", "A", "B", "A"))

'

' Ïðîâåðêè

'

    I = Len(Code)

If I = 12 Then

'

'Ðàñ÷åò êîíòðîëüíîé öèôðû

'

      CountParity = 0                                         '

    For I = 2 To 12 Step 2                                    'ñêëàäûâàåì

      CountParity = CountParity + Int(Mid(Code, I, 1))        '÷åòíûå öèôðû

    Next I                                                    '

      CountNotParity = 0                                      '

    For I = 1 To 11 Step 2                                    'ñêëàäûâàåì

      CountNotParity = CountNotParity + CInt(Mid(Code, I, 1)) 'íå÷åòíûå öèôðû

    Next I                                                    '

        ControlData = CountParity * 3 + CountNotParity        'Ñóììà öèôð íà ÷åòíûõ è íå÷åòíûõ ïîçèöèÿõ

        R = ControlData / 10        'Ðåçóëüòàò äåëåíèÿ ÷åòíûõ è íå÷åòíûõ öèôð íà 10

        If R - Int(R) = 0 Then      'Åñëè ÷èñëî êðàòíî 10

            ControlData = 0         'òî êîíòðîëüíîå ÷èñëî íàéäåíî

        Else                        'åñëè íåò, òî

            I = 0

            Do                             'äîïîëíÿåì

             I = I + 1                     '÷èñëî,

             ControlData = ControlData + 1 'äî áëèæàéøåãî

             R = ControlData / 10          'êðàòíîãî 10

             If R - Int(R) = 0 Then        '

                ControlData = I

             Exit Do

             End If

            Loop                           '

        End If

     ControlData = ControlData

'

'Ñáîðêà øòðèõ-êîäà

'

    j = CInt(Mid(Code, 1, 1))              '(13ýë) Èñïîëíåíèå öèôðîâûõ çíàêîâ

 

    BarCode = Chr(Asc(Mid(Code, 1, 1)) - 13)                'Ôëàã êîäà, öèôðà áåç øòðèõà

    BarCode = BarCode & "!"                                          'Êðàåâîé çíàê

    BarCode = BarCode & (A(CInt(Mid(Code, 2, 1))))  '(12ýë) âñåãäà À

   For I = 1 To 5                                    'Êîäèðóåì ñëåäóþùèå 5 ýëåìåíòîâ

    If ISP(j)(I) = "A" Then

       BarCode = BarCode & (A(CInt(Mid(Code, I + 2, 1)))) 'ýëåìåíò À

    Else

       BarCode = BarCode & (B(CInt(Mid(Code, I + 2, 1)))) 'ýëåìåíò B

    End If

   Next I

    BarCode = BarCode & "-"            'Ðàçäåëèòåëüíûé çíàê

  For I = 8 To 12                                   'Êîäèðóåì ñëåäóþùèå 6 ýëåìåíòîâ

    BarCode = BarCode & (C(CInt(Mid(Code, I, 1))))  '

  Next I

    BarCode = BarCode & C(ControlData)        'Êîíòðîëüíàÿ öèôðà

    BarCode = BarCode & "!"                            'Êðàåâîé çíàê

Else

'

' åñëè ÷èñëî ïîçèöèé â êîäå íå 12

'

End If

End Sub

 

! Ñì. òàêæå:

17.4 Ðàáîòà ñî øòðèõ-êîäàìè