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

 

Ìàêðîñ «Íàéòè ïîçèöèè ïî øòðèõ-êîäó»

 

Èñïîëüçóåòñÿ äëÿ ïîèñêà ïîçèöèè â áàçå äàííûõ ñ èñïîëüçîâàíèåì ôóíêöèè API GetCatalogIdByBarCode.

 

Sub FormMacro_NBarCodeMark(TCSActiveModule) 
'
' Ïîèñê è âûäåëåíèå íîìåíêëàòóðû ïî øòðèõ-êîäó 
'
' ÏÐÈÌÅÐ ÈÑÏÎËÜÇÎÂÀÍÈß ÔÓÍÊÖÈÈ GetCatalogIdByBarCode
'
'
    Dim I,J,K,L    'Ñëóæåáíûå ïåðåìåííûå
    Dim IBar       'Øòðèõ-êîä
    Dim IStr       'Ñëóæåáíàÿ ñòðîêîâàÿ ïåðåìåííàÿ 
    Dim JStr       'Ñëóæåáíàÿ ñòðîêîâàÿ ïåðåìåííàÿ
    Dim RowsCount  'Êîëè÷åñòâî âûäåëåííûõ çàïèñåé
    Dim CatalogName'Íàçâàíèå ñïðàâî÷íèêà â êîòîðîì íàõîäèòñÿ øòðèõ-êîä
    Dim ID1,ID2    'Èäåíòèôèêàòîðû íàéäåíûõ çàïèñåé 
    Dim KeyProperties(0) 'Ìàññèâ íàçâàíèé ïðîïåðòåé, ïî êîòîðûì îñóùåñòâëÿåòñÿ ïîèñê    
    Dim KeyValues(0)     'Ìàññèâ çíà÷åíèé ïðîïåðòåé, ïî êîòîðûì îñóùåñòâëÿåòñÿ ïîèñê
 
    KeyProperties(0) = "ID"                    'Ïðîïåðòè, ïî êîòîðûì 
                                               'áóäåò îñóùåñòâîÿòüñÿ ïîèñê 
    RowsCount=0                                              'Ñ÷åò÷èê çàïèñåé
    IBar=""                                                  'Øòðèõ-êîä
    While IBar <> "????????????????"                         'Øàáëîí øòðèõ-êîäà äëÿ ïîçèöèè íîìåíêëàòóðíîãî ñïðàâî÷íèêà
    IBar=TCSApp.InputBox("Ââåäèòå øòðèõ-êîä","Çàïèñü:" + Cstr(RowsCount)+ "  Êîä:" + IBar,"????????????????")'Ââåñòè Øòðèõ-êîä   
       If IBar <> "????????????????" Then                    'Åñëè íè÷åãî íå ââåäåíî, òî êîíåö ðàáîòû
         IStr=Mid(IBar,1,1)
         JStr=Mid(IBar,Len(IBar),1) 
'         
' Áëîê äëÿ ñêàíåðîâ, êîòîðûå íå ïîíèìàþò ñòîï-êîäû
'
              If IStr="d" And JStr="d" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If
              If IStr="D" And JStr="D" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If
              If IStr="d" And JStr="e" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If
              If IStr="D" And JStr="E" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If                          
              If IStr="a" And JStr="a" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If
              If IStr="A" And JStr="A" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If
              If IStr="a" And JStr="t" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If                
              If IStr="A" And JStr="T" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If                       
              If IStr="b" And JStr="b" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If
              If IStr="B" And JStr="B" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If
              If IStr="b" And JStr="n" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If
              If IStr="B" And JStr="N" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If                          
              If IStr="c" And JStr="c" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If
              If IStr="C" And JStr="C" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If
              If IStr="c" And JStr="*" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If                
              If IStr="C" And JStr="*" Then
               IBar=Mid(IBar,2,(Len(IBar)-2))
              End If                       
'
' Êîíåö áëîêà äëÿ ñêàíåðîâ, êîòîðûå íå ïîíèìàþò ñòîï-êîäû
'          
           CatalogName=""
        If TCSApp.GetCatalogIdByBarCode (IBar,CatalogName,ID1,ID2) Then             'Ïîèñê ïî øðèõ-êîäó
          If CatalogName="Nomenclatures" Then                    'Åñëè ýòî íîìåíêëàòóðà
              KeyValues(0)=ID1                                                      'ID îáíàðóæåííîé ïîçèöèè
           If TCSActiveModule.Locate(KeyProperties, KeyValues, 0) Then              'Ïîèñê íîìåíêëàòóðíîé ïîçèöèè 
              TCSActiveModule.CurrentRowSelected = True     'Âûäåëèòü ñòðîêó
              RowsCount=RowsCount+1                          'Äîáàâèòü â êîëè÷åñòâî âûäåëåííûõ çàïèñåé 
           Else
           Call TCSApp.ShowMessageBox("Ñîîáùåíèå", " äàííîì ñïðàâî÷íèêå íåò çàïèñè ñ òàêèì êîäîì!")
           End If
          Else
           Call TCSApp.ShowMessageBox("Ñîîáùåíèå", "Äàííàÿ ïîçèöèÿ íàõîäèòñÿ â ñïðàâî÷íèêå " + CatalogName +" !")
          End If 
        Else
        Call TCSApp.ShowMessageBox("Ñîîáùåíèå", "Â áàçå äàííûõ íåò çàïèñè ñ òàêèì êîäîì!")
        End If
       End If 
    Wend 
End Sub

 

Ìàêðîñ «Íàéòè ïîçèöèè ïî øòðèõ-êîäó EAN13»

 

Èñïîëüçóåòñÿ äëÿ ïîèñêà â áàçå äàííûõ ïîçèöèè, çàêîäèðîâàííûõ êîäîì EAN13 âíåøíèì àëãîðèòìîì, êàê ýòî ïîêàçàíî â ïðèìåðå 18.4.2.  äàííîì ìàêðîñå ñêàíåðîì ñ÷èòûâàåòñÿ êîä, ðàñêîäèðóåòñÿ äëÿ ïîëó÷åíèÿ èäåíòèôèêàòîðà ïîçèöèè è ïîèñê îñóùåñòâëÿåòñÿ ïî ýòîìó èäåíòèôèêàòîðó ñ ïîìîùüþ ôóíêöèè API Locate.

 

Sub FormMacro_NBarCodeMark_EAN13(TCSActiveModule) 
'
' Ïîèñê è âûäåëåíèå íîìåíêëàòóðû ïî øòðèõ-êîäó EAN13 
'
' ÏÐÈÌÅÐ ÈÑÏÎËÜÇÎÂÀÍÈß ÂÍÅØÍÅÃÎ ÊÎÄÀ È ÔÓÍÊÖÈÈ Locate 
'                  
'
    Dim I,J,K,L    'Ñëóæåáíûå ïåðåìåííûå
    Dim IBar       'Øòðèõ-êîä
    Dim IStr       'Ñëóæåáíàÿ ñòðîêîâàÿ ïåðåìåííàÿ
    Dim RowsCount  'Êîëè÷åñòâî âûäåëåííûõ çàïèñåé 
    Dim KeyProperties(0) 'Ìàññèâ íàçâàíèé ïðîïåðòåé, ïî êîòîðûì îñóùåñòâëÿåòñÿ ïîèñê    
    Dim KeyValues(0)     'Ìàññèâ çíà÷åíèé ïðîïåðòåé, ïî êîòîðûì îñóùåñòâëÿåòñÿ ïîèñê
 
    KeyProperties(0) = "ID"                    'Ïðîïåðòè, ïî êîòîðûì 
                                               'áóäåò îñóùåñòâîÿòüñÿ ïîèñê
    RowsCount=0                                       'Ñ÷åò÷èê çàïèñåé
    IBar=""                                                  'Øòðèõ-êîä
    While IBar <> "0???????????X"                          'Øàáëîí øòðèõ-êîäà äëÿ ïîçèöèè ïëàíà
    IBar=TCSApp.InputBox("Ââåäèòå øòðèõ-êîä","Çàïèñü:" + Cstr(RowsCount)+ "  Êîä:" + IBar,"0???????????X")'Ââåñòè Øòðèõ-êîä   
    If Len(IBar) = 12 Then IBar="0" & IBar             'Íåêîòîðûå ñêàíåðû íå ÷èòàþò ïåðâûé "0"
    IStr=Mid(IBar,1,1)                                       'Ïåðâûé ñèìâîë äîëæíû áûòü "0", ÷òî îçíà÷àåò ïðèçíàê íîìåíêëàòóðû
       If IBar <> "0???????????X" Then                     'Åñëè íè÷åãî íå ââåäåíî, òî êîíåö ðàáîòû
        If IStr <> "0" Or Len(IBar) <> 13 Then               'Åñëè êîä íå óäîâëåòâîðÿåò óñëîâèÿì
          Call TCSApp.ShowMessageBox("Ñîîáùåíèå", "Äàííûé êîä " + IBar + " íå ÿâëÿåòñÿ êîäîì ïîçèöèè íîìåíêëàòóðíîãî ñïðàâî÷íèêà")
          IBar=""                                            '
        Else                                                 '
          IStr=Mid(IBar,2,11)                      'Âûäåëèòü ID íîìåíêëàòóðû èç øòðèõ-êîäà 
          L="0"                                             'è óáðàòü èç íåãî ëèäèðóþùèå íóëè
          I=0                                                   '
          While L="0"                                  '
            L=Mid(IStr,I+1,1)                       'Ïåðåáèðàòü ñëåâà íà ïðàâî IStr
            I=I+1                                             'ïîêà íå êîí÷àòñÿ íóëè
          Wend                                               '
          K=Len(IStr)-I+1                             'Äëèíà óíèêàëüíîãî êîäà
          IStr= Mid(IStr,I,K)                        'Âûäåëèòü óíèêàëüíûé êîä áåç íóëåé è êîíòðîëüíîé ñóììû  
              If IStr="" Then
                  KeyValues(0)=0
              Else
                  KeyValues(0)=IStr                  'Ðàñêîäèðîâàííûé ID äëÿ ïîèñêà
              End If
           If TCSActiveModule.Locate(KeyProperties, KeyValues, 0) Then      'Ïîèñê íîìåíêëàòóðíîé ïîçèöèè 
              TCSActiveModule.CurrentRowSelected = True      'Âûäåëèòü ñòðîêó
              RowsCount=RowsCount+1                          'Äîáàâèòü â êîëè÷åñòâî âûäåëåííûõ çàïèñåé 
           Else
           Call TCSApp.ShowMessageBox("Ñîîáùåíèå", " äàííîì ñïðàâî÷íèêå íåò çàïèñè ñ òàêèì êîäîì!")
           End If
        End If
       End If 
    Wend 
 End Sub

 


! Ñì. òàêæå:

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