Äëÿ âûïîëíåíèÿ äàííîãî ìàêðîñà, íóæíî â ðåæèìå âåäåíèÿ íîìåíêëàòóðíîãî ñïðàâî÷íèêà îòìåòèòü  ïîçèöèè, êîòîðûì áóäåò ïðèñâàèâàòüñÿ øòðèõ-êîä, è çàïóñòèòü ìàêðîñ «Íàçíà÷èòü êîä EAN13 âûäåëåííûì ïîçèöèÿì íîìåíêëàòóðû».

Äàííûé ïðèìåð èëëþñòðèðóåò èñïîëüçîâàíèå âíåøíåãî êîäà (êîäà, çàäàâàåìîãî ïîëüçîâàòåëåì), ïîñòðîåííîãî íà îñíîâå èìåþùèõñÿ â áàçå äàííûõ èäåíòèôèêàòîðîâ íîìåíêëàòóðû äëÿ ïîëó÷åíèÿ óíèêàëüíûõ 12-ðàçðÿäíûõ êîäîâûõ êîìáèíàöèé êîäà EAN13.

 

Sub FormMacro_NBarCodeINS_EAN13(TCSActiveModule)

'

' Íàçíà÷åíèå øòðèõ-êîäà EAN13 âûäåëåííûì ïîçèöèÿì íîìåíêëàòóðû

'

' ÏÐÈÌÅÐ ÈÑÏÎËÜÇÎÂÀÍÈß ÂÍÅØÍÅÃÎ ÊÎÄÀ (ÊÎÄÀ ÇÀÄÀÂÀÅÌÎÃÎ ÏÎËÜÇÎÂÀÒÅËÅÌ)

'

' Ôîðìàò êîäà:  0ÕÕÕÕÕÕÕÕÕÕÕ

'                             

'               0 - ïðèçíàê òîãî, ÷òî êîä îòíîñèòñÿ ê íîìåíêëàòóðíîé ïîçèöèè

'     ÕÕÕÕÕÕÕÕÕÕÕ - 11 ñèìâîëîâ ID íîìåíêëàòóðû        

'  

    Dim I,J,K,L,M             'Ñëóæåáíûå ïåðåìåííûå

    Dim BarCodes             'Øòðèõ-êîäû îáúåêò                           

    Dim RowsCount          'Êîëè÷åñòâî âûäåëåííûõ çàïèñåé

    Dim msBM()                'Ìàññèâ ññûëîê íà âûäåëåííûå çàïèñè

    Dim IBar          'Øòðèõ-êîä

    Dim IStr           'Ñëóæåáíàÿ ñòðîêîâàÿ ïåðåìåííàÿ

   

    RowsCount = TCSActiveModule.SelectedRowsCount                   ' Çàïîìíèòü êîëè÷åñòâî âûäåëåííûõ çàïèñåé

    If RowsCount > 0 Then                                           ' Åñëè âûäåëåííûå çàïèñè åñòü, òî

        Redim msBM( RowsCount - 1 )                          ' Îïðåäåëèòü íåîáõîäèìûé ðàçìàð ìàññèâà äëÿ çàïîìèíàíèÿ ññûëîê

        For I = 0 To RowsCount - 1                                  ' Ïåðåáðàòü âûäåëåííûå çàïèñè ñïåöèôèêàöèè

            If TCSActiveModule.GotoSelectedRow(I) Then              ' Âñòàòü íà î÷åðåäíóþ âûäåëåííóþ çàïèñü

                msBM( I ) = TCSActiveModule.GetBookmark             ' È çàïîìíèòü åå â ìàññèâå

            End If                                                  '

        Next                                                        ' 

        TCSActiveModule.Refresh                                     ' Cáðîñèòü âûäåëåíèå 

            K=0                                                     ' Ñ÷åò÷èê çàïèñåé

        For I = 0 To RowsCount - 1                                  ' Èäòè ïî ìàññèâó ññûëîê

           Call TCSActiveModule.GotoBookmark( msBM( I ) )           ' Ïîçèöèîíèðîâàòüñÿ íà òåêóùóþ çàïèñü

               Set BarCodes = TCSActiveModule.Properties("BarCodes").AsIDispatch

               If BarCodes.Properties( "BAR_CODE" ).IsNull Then     ' Åñëè ó ïîçèöèè íåò øòðèõ-êîäà

                   K=K+1                                      ' Äîáàâëÿåì ñ÷åò÷èê

                   IStr=Cstr(TCSActiveModule.Properties( "ID" ).AsInteger)'Èäåíòèôèêàòîð íîìåíêëàòóðû

                   If Len(IStr)>11  Then                     ' Åñëè èäåíòèôèêàòîð ñëèøêîì äëèííûé òî

                   Call TCSApp.ShowMessageBox("Ñîîáùåíèå", "Êîä EAN13 íå ìîæåò îáåñïå÷èòü óíèêàëüíîñòü ïîçèöèè")

                 Else                                         ' Åñëè äî 11 ñèìâîëîâ, òî

                   For L=1 To 11-Len(IStr)             ' Ñôîðìèðîâàòü óíèêàëüíûé êîä 

                    IStr="0" & IStr                           ' Äîïîëíèòü êîä íóëÿìè

                   Next                                       '

                         IStr="0" & IStr                      ' Äëÿ îáåñïå÷åíèÿ óíèêàëüíîñòè øòðèõ-êîäû â íîìåíêëàòóðå áóäåì íà÷èíàòü ñ "0"

                 End If                                       '

                    Call BarCodes.CreateNew                         ' Ñîçäàäèì íîâóþ çàïèñü â øòðèõ-êîäå

                      BarCodes.Properties("BAR_CODE").Value = IStr  ' Ïðèñâîèì øòðèõ-êîä

                      BarCodes.Properties("DEFAULT").Value = "T"    ' Ñäåëàåì åãî îñíîâíûì

                      BarCodes.Properties("REM").Value = "EAN13"    ' Çàíåñåì êîììåíòàðèé

                      On Error Resume Next                          ' è

                    Call BarCodes.SaveChanges                       ' Ñîõðàíèì èçìåíåíèÿ

                    Call BarCodes.CancelChanges                     '  ñëó÷àå îøèáêè îòìåíèì èõ

               End If                                         '

               Set BarCodes = Nothing                         '

        Next                                                  ' Âçÿòü íîâóþ çàïèñü

        For I = 0 To RowsCount - 1                            ' Èäòè ïî ìàññèâó ññûëîê

            Call TCSActiveModule.GotoBookmark( msBM( I ) ) ' Ïîçèöèîíèðîâàòüñÿ íà òåêóùóþ çàïèñü

            TCSActiveModule.CurrentRowSelected = True         ' Âåðíóòü âûäåëåíèå ñòðîêè

        Next                                                  '

        Call TCSApp.ShowMessageBox("Ñîîáùåíèå", "Øòðèõ-êîä íàçíà÷åí äëÿ " + Cstr(K) + " çàïèñåé")

        If K=0 Then

          Call TCSApp.ShowMessageBox("Ñîîáùåíèå", "Âûäåëåííûì ïîçèöèÿì íîìåíêëàòóðû øòðèõ-êîä óæå áûë íàçíà÷åí")

        End If

    Else                                                      ' Åñëè âûäåëåííûõ çàïèñåé íåò

        Call TCSApp.ShowMessageBox("Ñîîáùåíèå", "Âûäåëèòå çàïèñè äëÿ êîòîðûõ íåîáõîäèìî óêàçàòü øòðèõ-êîäû")

    End If                                                    '

End Sub

 

! Ñì. òàêæå:

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