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

Äàííûé ïðèìåð èëëþñòðèðóåò èñïîëüçîâàíèå ôóíêöèè TCSApp.BarCodeGen, êîòðàÿ âîçâðàùàåò óíèêàëüíîå ÷èñëî äëÿ èñïîëüçîâàíèÿ â ñïðàâî÷íèêå øòðèõ-êîäîâ.

 

Sub FormMacro_NBarCodeINS(TCSActiveModule)

'

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

'

' Ñ èñïîëüçîâàíèåì ôóíêöèè TCSApp.BarCodeGen, êîòðàÿ âîçâðàùàåò óíèêàëüíîå ÷èñëî

' äëÿ èñïîëüçîâàíèÿ â ñïðàâî÷íèêå øòðèõ-êîäîâ                            

'

'

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

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

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

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

  

    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                                            ' Äîáàâëÿåì ñ÷åò÷èê

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

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

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

                      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 Ðàáîòà ñî øòðèõ-êîäàìè