Alpha DevCon 2018
Results 1 to 14 of 14

Thread: Barcoding code128

  1. #1
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,107

    Default Barcoding code128

    The attached files are similar to Ira Perlow's UPCAFont functions, in fact Ira contributed changes
    which condensed and doubled the speed of my working functions.


    The implementation of Code128 barcoding represented here is limited to Type C. Type C handles

    number pairs 00-99. If you attempt to barcode the string "001", the result will be the barcode for

    "0001". I plan to work on a full implementation of Code128 as time permits.


    The encoded strings which are the results of these functions map to the CIA Code 128 fonts.

    Visit their website http://www.snx.com/demos.html for this font.


    Enjoy.

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,107

    Default RE: Barcoding code128

    I've made a couple of changes to strip out alphabetic characters entered (accidentally ?) to make sure the function works as intended. If a purely alphabetic string is processed for encoding, the function will encode "00".

  3. #3
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,107

    Default RE: Barcoding code128

    The previous file also includes the demo version of a program with the barcode fonts, as mentioned in the first post.

  4. #4
    Member
    Real Name
    Neil Rubin
    Join Date
    Jan 2013
    Posts
    7

    Default Re: Barcoding code128

    Hi Stan
    I need to use a code 128 barcode within a label (preferably Id automations c128L)and I am wondering if your functions will encode my 24 digit string to use with the barcode font. I can generate the 24 digits but need the function that will encode it properly.

    Any guidance will be greatly appreciated.

    Neil

  5. #5
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,107

    Default Re: Barcoding code128

    That was a long time ago. Worth a try.
    There can be only one.

  6. #6
    Member
    Real Name
    Neil Rubin
    Join Date
    Jan 2013
    Posts
    7

    Default Re: Barcoding code128

    Do you have a sample xbasic script that incorporates these functions?

  7. #7
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,107

    Default Re: Barcoding code128

    As functions you use them like any other. Save/create them on the code tab.

    You define a calculated field for your label. The expression for the calculated field is

    code128(fieldvaluetobebarcoded)

    Place the calculated field on the label and set the proper font.

    I think the second function was the checksum calculator.
    There can be only one.

  8. #8
    Member
    Real Name
    Neil Rubin
    Join Date
    Jan 2013
    Posts
    7

    Default Re: Barcoding code128

    Thanks Stan. I'll give it a try. Is it useable with any c128 font? Or is there a specific one you used for this function ?

  9. #9
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,107

    Default Re: Barcoding code128

    The encoded strings which are the results of these functions map to the CIA Code 128 fonts.
    Don't have any others to test.
    There can be only one.

  10. #10
    Member
    Real Name
    Neil Rubin
    Join Date
    Jan 2013
    Posts
    7

    Default Re: Barcoding code128

    Hi Stan
    I tried out your fuctions and the second function does do the check digit part of the barcode which is called from the first encoding function. I believe the math calculations to create the pairs of numbers is correct however the resulting text string is not. From my research I believe that once you build the number string with the check digit you have to pair up the numbers and assign the correct ascii character. ie replace a pair of 90 with a "z" - you have to do this for each pair using a loop. In your function you sting together a rather long looking set of characters that I can figure out.

    Any ideas on this?

    neil

  11. #11
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,107

    Default Re: Barcoding code128

    The function processes the number string and tacks on the encoded check digit as the final step.

    This section processes the number pairs to encoded values.

    Code:
    for i = 1 to pairs
    ' ***************** Simplify pair selection
    	prs=substr(F128n,(i*2)-1,2)
           
    	' Get the character for the font for the ith position in the barcode and
            
    	fontchar=SUBSTR(chr0099,(VAL(prs)*2)+1,2)
    	fontstg=fontstg+fontchar
    
    next
    If your font uses different encoding you need to change the part that builds the substiturion string chr0099.
    There can be only one.

  12. #12
    Member
    Real Name
    Neil Rubin
    Join Date
    Jan 2013
    Posts
    7

    Default Re: Barcoding code128

    Do you think that using a lookup to a table that has the two digit pairs and the corresponding ASCII character or using a case statement to do the lookup to return the two digit pairs ASCII equivalent could work too to build the encoding string? I have the ascii map for my font. Here is the mapping.

    http://www.barcoderesource.com/code128_barcode_map.html

  13. #13
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    321

    Default Re: Barcoding code128

    Both of these links are invalid. What is the function used to calculate code128?

    I found this but it seems like it will need some modification before it can be used as a function in alpha.

    Code:
      Public Function Code128$(chaine$)
      'V 2.0.0
        'Parameters : a string
      'Return : * a string which give the bar code when it is dispayed with CODE128.TTF font
      '         * an empty string if the supplied parameter is no good
      Dim i%, checksum&, mini%, dummy%, tableB As Boolean
      Code128$ = ""
      If Len(chaine$) > 0 Then
      'Check for valid characters
        For i% = 1 To Len(chaine$)
          Select Case Asc(Mid$(chaine$, i%, 1))
          Case 32 To 126, 203
          Case Else
            i% = 0
            Exit For
          End Select
        Next
        'Calculation of the code string with optimized use of tables B and C
        Code128$ = ""
        tableB = True
        If i% > 0 Then
          i% = i% become the string index
          Do While i% <= Len(chaine$)
            If tableB Then
              'See if interesting to switch to table C
              'yes for 4 digits at start or end, else if 6 digits
              mini% = IIf(i% = 1 Or i% + 3 = Len(chaine$), 4, 6)
              GoSub testnum
              If mini% < 0 Then 'Choice of table C
                If i% = 1 Then 'Starting with table C
                  Code128$ = Chr$(210)
                Else 'Switch to table C
                  Code128$ = Code128$ & Chr$(204)
                End If
                tableB = False
              Else
                If i% = 1 Then Code128$ = Chr$(209) 'Starting with table B
              End If
            End If
            If Not tableB Then
              'We are on table C, try to process 2 digits
              mini% = 2
              GoSub testnum
              If mini% < 0 Then 'OK for 2 digits, process it
                dummy% = Val(Mid$(chaine$, i%, 2))
                dummy% = IIf(dummy% < 95, dummy% + 32, dummy% + 105)
                Code128$ = Code128$ & Chr$(dummy%)
                i% = i% + 2
              Else 'We haven't 2 digits, switch to table B
                Code128$ = Code128$ & Chr$(205)
                tableB = True
              End If
            End If
            If tableB Then
              'Process 1 digit with table B
              Code128$ = Code128$ & Mid$(chaine$, i%, 1)
              i% = i% + 1
            End If
          Loop
          'Calculation of the checksum
          For i% = 1 To Len(Code128$)
            dummy% = Asc(Mid$(Code128$, i%, 1))
            dummy% = IIf(dummy% < 127, dummy% - 32, dummy% - 105)
            If i% = 1 Then checksum& = dummy%
            checksum& = (checksum& + (i% - 1) * dummy%) Mod 103
          Next
          'Calculation of the checksum ASCII code
          checksum& = IIf(checksum& < 95, checksum& + 32, checksum& + 105)
          'Add the checksum and the STOP
          Code128$ = Code128$ & Chr$(checksum&) & Chr$(211)
        End If
      End If
      Exit Function
    testnum:
      'if the mini% characters from i% are numeric, then mini%=0
      mini% = mini% - 1
      If i% + mini% <= Len(chaine$) Then
        Do While mini% >= 0
          If Asc(Mid$(chaine$, i% + mini%, 1)) < 48 Or Asc(Mid$(chaine$, i% + mini%, 1)) > 57 Then Exit Do
          mini% = mini% - 1
        Loop
      End If
    Return
    End Function
    Last edited by hov333; 11-29-2016 at 12:17 PM.

  14. #14
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,107

    Default Re: Barcoding code128

    I didn't install the code128.ttf so I haven't tested it but I made a stab at translating the function.

    code128 - 11-29-2016 -1.txt
    There can be only one.

Similar Threads

  1. Checksum Algorithm for Code128
    By Ed in forum Alpha Five Version 5
    Replies: 7
    Last Post: 01-28-2013, 10:23 PM
  2. Barcoding
    By davidhp in forum Alpha Five Version 5
    Replies: 2
    Last Post: 11-05-2002, 09:40 AM
  3. Barcoding in V 6
    By Veronica Perez in forum Alpha Four Version 6 and Prior
    Replies: 2
    Last Post: 07-02-2002, 06:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •