Public Function bcUPC(ByVal arg_input As Variant) As String Dim as_input As String Dim ls_Start, ls_Left, ls_Right, ls_Stop As String Dim ll_Count, ll_Max Dim ls_Codes As String Dim ll_Odd, ll_Even, ll_Check As Long ' make sure that you are not dealing with a null character as_input = UCase(Trim(arg_input & "")) ls_Start = "0123456789" ls_Left = "PQWERTYUIO" ls_Right = ";ASDFGHJKL" ls_Stop = "/ZXCVBNM,." 'add 0's to the left if 11 characters are passed in as_input = Right(String(11, "0") & as_input, 11) 'if the input isn't numeric then return the empty string If Not IsNumeric(as_input) Then ls_Codes = "" Else ll_Max = Len(as_input) For ll_Count = 1 To ll_Max Select Case ll_Count Case 1 'the first character comes from the first row of the keyboard ls_Codes = ls_Codes & Mid(ls_Start, Mid(as_input, ll_Count, 1) + 1, 1) Case 2, 3, 4, 5, 6 ' the 2nd through 6th come from the second row ls_Codes = ls_Codes & Mid(ls_Left, Mid(as_input, ll_Count, 1) + 1, 1) If ll_Count = 6 Then ls_Codes = ls_Codes + "-" Case 7, 8, 9, 10, 11 ' the 7th through 11th come from the third row ls_Codes = ls_Codes & Mid(ls_Right, Mid(as_input, ll_Count, 1) + 1, 1) End Select Next 'calculate the sum of the odd characters ll_Odd = Int(Mid(as_input, 1, 1)) ll_Odd = ll_Odd + Int(Mid(as_input, 3, 1)) ll_Odd = ll_Odd + Int(Mid(as_input, 5, 1)) ll_Odd = ll_Odd + Int(Mid(as_input, 7, 1)) ll_Odd = ll_Odd + Int(Mid(as_input, 9, 1)) ll_Odd = ll_Odd + Int(Mid(as_input, 11, 1)) 'calculate the sum of the even characters ll_Even = Int(Mid(as_input, 2, 1)) + Int(Mid(as_input, 4, 1)) ll_Even = ll_Even + Int(Mid(as_input, 6, 1)) + Int(Mid(as_input, 8, 1)) ll_Even = ll_Even + Int(Mid(as_input, 10, 1)) 'calculate the check digit based on the UPC symbology ll_Check = 10 - (((ll_Odd * 3) + (ll_Even)) Mod 10) If ll_Check = 10 Then ll_Check = 0 'attach the check digit to the barcode ls_Codes = ls_Codes & Mid(ls_Stop, ll_Check + 1, 1) End If bcUPC = ls_Codes End Function Public Function bc3of9(ByVal arg_input As Variant) As String Dim as_input As String Dim ll_Count As Long Dim ls_Codes As String 'trim the codes and set it to upper case as_input = Trim(UCase(arg_input & "")) 'walk through the codes removing all invalid codes For ll_Count = 1 To Len(as_input) ls_Char = Mid(as_input, ll_Count, 1) If ls_Char = " " Then ls_Char = "~" If InStr(1, "~ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890%$-./+", ls_Char) Then ls_Codes = ls_Codes & ls_Char End If Next 'attach the *'s if there is any codes produced If Len(ls_Codes) > 0 Then ls_Codes = "*" & ls_Codes & "*" Else ls_Codes = "" bc3of9 = ls_Codes End Function Public Function bc2of5(as_input As String) As String Dim ll_length As Long Dim ll_checkdigit As Long Dim ll_CharMap As Long Dim ls_ConvertedString As String Dim ls_Char As String 'trim the input to have no spaces on the left and right as_input = Trim(as_input) 'convert the input to numeric if it is not already If Not IsNumeric(as_input) Then as_input = "00" 'get the length of the input ll_length = Len(as_input) ' the input has got to be an even number of characters If Not ll_length Mod 2 = 0 Then as_input = "0" & as_input ll_length = ll_length + 1 End If ll_i = 1 'convert the characters While ll_i <= ll_length ll_CharMap = Int(Mid(as_input, ll_i, 2)) ll_i = ll_i + 2 'set the character offset Select Case ll_CharMap Case 0 To 80 ll_CharMap = ll_CharMap + 46 'for numbers 0 to 80, the offset is 46 Case 81 To 99 ll_CharMap = ll_CharMap + 80 'for numbers 81 on, the offset is 80 End Select ' set the string to add the new character map ls_Char = Chr(ll_CharMap) ls_ConvertedString = ls_ConvertedString + ls_Char Wend bc2of5 = "+" & ls_ConvertedString & "-" End Function