Converting UPC-A to UPC-E using Visual Basic

Below is a function that when passed an 12 digit UPC-A code will return the zero supressed 8 digit UPC-E code. Feel free to use the code, just remember where you got it from and leave my name in the code. Thanks!

I also have a function to go from UPC-E to UPC-A.

Public Function UPCA2UPCE(ByVal UPCA As String) As String
    '
    ' Convert UPC-A to UPC-E format
    '
    ' Written by Glenn J. Schworak (www.schworak.com)
    '
    Dim ValidDigits As String
    Dim Mfg As String
    Dim Prod As String
    Dim x As Integer
    
    If Len(UPCA) <> 12 Or (Left(UPCA, 1) <> "0" And Left(UPCA, 1) <> "1") Or _
       InStr(1, Mid(UPCA, 5, 8), "0000") < 1 Then
        UPCA2UPCE = "INVALID"
    Else
        Mfg = Mid(UPCA, 2, 5)
        Prod = Mid(UPCA, 7, 5)
        If Right(Mfg, 3) = "000" Or Right(Mfg, 3) = "100" Or Right(Mfg, 3) = "200" Then
            ValidDigits = Left(Mfg, 2) & Right(Prod, 3) & Mid(Mfg, 3, 1)
        ElseIf Right(Mfg, 2) = "00" Then
            ValidDigits = Left(Mfg, 3) & Right(Prod, 2) & "3"
        ElseIf Right(Mfg, 1) = "0" Then
            ValidDigits = Left(Mfg, 4) & Right(Prod, 1) & "4"
        Else
            ValidDigits = Left(Mfg, 5) & Right(Prod, 1)
        End If
        UPCA2UPCE = Left(UPCA, 1) & ValidDigits & Right(UPCA, 1)
    End If
End Function

If you want to use this function in .Net, you will need to prefix the LEFT and RIGHT commands with vb. to get them to work properly. There may be other changes needed as well. The function above is for reference purposes. Adapt it to your specific language as needed.

 UPC Code 
 Key Code  Remember 
 Description 

Was This Page Helpful?

Please take a moment to help us improve our service by filling in a short survey. This is totally optional but offers valuable feedback. Your opinion really matters to us.

Your Opinion Matters
Rating: This Page The Site In General
Rank: No Rank Awful! Poor Fair Good Awesome!
Comment:
optional
500 char
limit
Email:
optional



Visit our other sites