OL Learn

Script to calculate upc-a check digit

I have this number “01580253300” in a text file (line1, position1). Is there a way to use a script to calculate the check digit ?

Hi @nabel1510,

Can you let me know please why you would like to calculate the check digit? Would you like to do that because you would like to add a UPC-A barcode element to a Template, for example? Please note that, when this is the case, you can add a UPC-A barcode element (with check digit included) to a Template by executing the following steps:

  1. Open a existing Template or create a new Template via the Connect Designer application.
  2. View the Master Page or Print Context Section to which you would like to add the UPC-A barcode element in Design mode.
  3. Go to Insert > Barcode > UPC-A to insert a UPC-A barcode element.
  4. Click with the right mouse button on the UPC-A barcode element and select the Barcode… option.
  5. Check the Human Readable Message option in case you would like to check the value assigned to the UPC-A barcode element.

Hi Marten

I need to add the human readable upc to the text document. I don’t want the barcode lines, only the numbers. I want to do it with workflow instead of designer because I want it to be faster

Hi nabel,

Something I slapped together to get you started. (VBScript) There is probably a more elegant way.

Dim num
Dim even
Dim odd
Dim result
Dim check

num = "69277198116" '"63938200039"

For i = 1 To Len(num)
    If i Mod 2 = 0 Then
        'Add even numbers
        even = CInt(even) + CInt(Mid(num, i, 1))
    Else
        'Add odd numbers
        odd = CInt(odd) + CInt(Mid(num, i, 1))
    End If
Next

'Multiply odd by three
odd = odd * 3

'Add the results
result = even + odd

'Whatever single digit number makes the total a multiple of 10 is the check digit.
check = CInt(Ceil(result / 10) * 10 - result)

watch.log check,2

Function Ceil(ByVal p_Number)
    Ceil = 0 - INT(0 - p_Number)
End Function

Sources: Link | Link

Regards,
S

Thks Sharne, I will try this.