Converting UPC-E back to UPC-A using Visual Basic

Below is a function that when passed an 8 digit UPC-E code will return the full 12 digit UPC-A code. This is very handy when you are looking up or wanting to use the UPC-A code but only have a UPC-E code to start with. 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-A to UPC-E.

Public Function UPCE2UPCA(ByVal UPCE As String) As String
    '
    ' Convert UPC-E to UPC-A format
    '
    ' Written by Glenn J. Schworak (www.schworak.com)
    '
    Dim ValidDigits As String
    Dim Mfg As String
    Dim Prod As String
    
    If Len(UPCE) <> 8 Or (Left(UPCE, 1) <> "0" And Left(UPCE, 1) <> "1") Then
        '
        ' Return INVALID instead of a UPC-A code
        '
        UPCE2UPCA = "INVALID"
    Else
        '
        ' Convert the UPC-E to UPC-A
        '
        ValidDigits = Mid(UPCE, 2, 6)
        Select Case Right(ValidDigits, 1)
            Case "0"
                Mfg = Left(ValidDigits, 2) & Right(ValidDigits, 1) & "00"
                Prod = "00" & Mid(ValidDigits, 3, 3)
            Case "1"
                Mfg = Left(ValidDigits, 2) & Right(ValidDigits, 1) & "00"
                Prod = "00" & Mid(ValidDigits, 3, 3)
            Case "2"
                Mfg = Left(ValidDigits, 2) & Right(ValidDigits, 1) & "00"
                Prod = "00" & Mid(ValidDigits, 3, 3)
            Case "3"
                Mfg = Left(ValidDigits, 3) & "00"
                Prod = "000" & Mid(ValidDigits, 4, 2)
            Case "4"
                Mfg = Left(ValidDigits, 4) & "0"
                Prod = "0000" & Mid(ValidDigits, 6, 1)
            Case Else
                Mfg = Left(ValidDigits, 5)
                Prod = "0000" & Mid(ValidDigits, 6, 1)
        End Select
        '
        ' Return the 12 digit UPC-A code
        '
        UPCE2UPCA = Left(UPCE, 1) & Mfg & Prod & Right(UPCE, 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