&&/*********************************************************************/ &&/* */ &&/* Morovia Foxpro Functions, part of Morovia Font Tools V2.1 */ &&/* (c)2000-2004 Morovia Corporation. All rights reserved. */ &&/* Visit http://www.morovia.com/font/ for more information. */ &&/* */ &&/* You may incorporate this source code in your application as long */ &&/* as you own a perpetual license to the font product. */ &&/* Distributing the source code, as well as its derivatives, require */ &&/* a developer license. */ &&/* Please refer to the license agreement for details. */ &&/*********************************************************************/ &&If you want to invoke these functions into your programme,please add this line in your programme &&SET PROCEDURE TO MoroviaFontTools.PRG ADDITIVE Function SpecialChar() para inpara i =0 strTemp ="" nLen =0 output="" nLen = Len(inpara) For i = 1 To nLen strTemp = subStr(inpara, i, 1) If strTemp = "\" then If i + 1 <= nLen And substr(inpara, i + 1, 1) = "\" output = output + "\" i = i + 1 Else If i + 3 <= nLen And Isdigit(substr(inpara, i + 1, 3)) output = output + Chr(Val(subStr(inpara, i + 1, 3))) i = i + 3 Else output = output + strTemp EndIf EndIf Else output = output + strTemp EndIf EndFor strTemp="" Return output Endfunc Function maskfilter() para inpara,coderange maskfilter = "" For i = 1 To Len(inpara) charPos = at( substr(inpara, i, 1),coderange) If charPos > 0 Then maskfilter = maskfilter + substr(inpara, i, 1) EndIf EndFor Return maskfilter Endfunc Function Parity5() para digit Do Case Case digit=0 Parity5 = "00111" Case digit=1 Parity5 = "01011" Case digit=2 Parity5 = "01101" Case digit=3 Parity5 = "01110" Case digit=4 Parity5 = "10011" Case digit=5 Parity5 = "11001" Case digit=6 Parity5 = "11100" Case digit=7 Parity5 = "10101" Case digit=8 Parity5 = "10110" Case digit=9 Parity5 = "11010" Endcase Return parity5 Endfunc Function LeftHandEncoding() para digit,parity do Case Case digit=0 If parity = 1 Then LeftHandEncoding = "/" Else If parity = 0 Then LeftHandEncoding = "?" EndIf EndIf Case digit=1 If parity = 1 Then LeftHandEncoding = "z" Else If parity = 0 Then LeftHandEncoding = "Z" EndIf EndIf Case digit=2 If parity = 1 Then LeftHandEncoding = "x" Else If parity = 0 Then LeftHandEncoding = "X" EndIf EndIf Case digit=3 If parity = 1 Then LeftHandEncoding = "c" Else If parity = 0 Then LeftHandEncoding = "C" EndIf EndIf Case digit=4 If parity = 1 Then LeftHandEncoding = "v" Else If parity = 0 Then LeftHandEncoding = "V" EndIf EndIf Case digit=5 If parity = 1 Then LeftHandEncoding = "b" Else If parity = 0 Then LeftHandEncoding = "B" EndIf EndIf Case digit=6 If parity = 1 Then LeftHandEncoding = "n" Else If parity = 0 Then LeftHandEncoding = "N" EndIf EndIf Case digit=7 If parity = 1 Then LeftHandEncoding = "m" Else If parity = 0 Then LeftHandEncoding = "M" EndIf EndIf Case digit=8 If parity = 1 Then LeftHandEncoding = "," Else If parity = 0 Then LeftHandEncoding = "<" EndIf EndIf Case digit=9 If parity = 1 Then LeftHandEncoding = "." Else If parity = 0 Then LeftHandEncoding = ">" EndIf EndIf Endcase Return lefthandencoding Endfunc Function UPC5SUPP() para inpara weightSum = 3 * Val(substr(inpara, 1, 1)) + 9 * Val(substr(inpara, 2, 1)) + 3 * Val(substr(inpara, 3, 1)) + 9 * Val(substr(inpara, 4, 1)) + 3 * Val(substr(inpara, 5, 1)) strParity = Parity5(mod(weightSum ,10)) UPC5SUPP = "{" For i = 1 To 5 UPC5SUPP = UPC5SUPP + LeftHandEncoding(Val(substr(inpara, i, 1)), Val(substr(strParity, i, 1))) If (i < 5) Then UPC5SUPP = UPC5SUPP + "\" EndIf EndFor Return upc5supp Endfunc Function Upce2upca() para digits upc2upca ="" For i=0 to 5 If not Isdigit(substr(digits, 2+i, 1)) Then Return 0 EndIf EndFor If (substr(digits, 1, 1) <> "0") or (Len(digits) <> 7) && "UPC-E must be leaded by 0 and followed by 6 numeric digits!" Return 0 EndIf do Case Case substr(digits, 7, 1)="0" Upce2upca = substr(digits, 1, 3) + substr(digits, 7, 1) + "0000" + substr(digits, 4, 3) Case substr(digits, 7, 1)="1" Upce2upca = substr(digits, 1, 3) + substr(digits, 7, 1) + "0000" + substr(digits, 4, 3) Case substr(digits, 7, 1)="2" Upce2upca = substr(digits, 1, 3) + substr(digits, 7, 1) + "0000" + substr(digits, 4, 3) Case substr(digits, 7, 1)="3" If at(substr(digits, 4, 1),"012")>0 Then && "Last digit is 3, then the Forth digit can not be 0,1,2!" Return 0 Else Upce2upca = substr(digits, 1, 4) + "00000" + substr(digits, 5, 2) EndIf Case substr(digits, 7, 1)="4" Upce2upca = substr(digits, 1, 5) + "00000" + substr(digits, 6, 1) Case substr(digits, 7, 1)="5" Upce2upca = substr(digits, 1, 6) + "0000" + substr(digits, 7, 1) Case substr(digits, 7, 1)="6" Upce2upca = substr(digits, 1, 6) + "0000" + substr(digits, 7, 1) Case substr(digits, 7, 1)="7" Upce2upca = substr(digits, 1, 6) + "0000" + substr(digits, 7, 1) Case substr(digits, 7, 1)="8" Upce2upca = substr(digits, 1, 6) + "0000" + substr(digits, 7, 1) Case substr(digits, 7, 1)="9" Upce2upca = substr(digits, 1, 6) + "0000" + substr(digits, 7, 1) otherwise && "The last digits of UPC-E code is not a numeric!" Return 0 Endcase Return upc2upca Endfunc Function UPC2SUPP( ) para inpara nTemp = mod(Val(inpara), 4) parity1=0 parity2=0 If nTemp = 0 Then parity1 = 1 parity2 = 1 Else If nTemp = 1 Then parity1 = 1 parity2 = 0 Else If nTemp = 2 Then parity1 = 0 parity2 = 1 Else If nTemp = 3 Then parity1 = 0 parity2 = 0 EndIf EndIf EndIf EndIf UPC2SUPP = "{" charToEncode = substr(inpara, 1, 1) UPC2SUPP = UPC2SUPP + LeftHandEncoding(Val(charToEncode), parity1) UPC2SUPP = UPC2SUPP + "\" charToEncode = substr(inpara, 2, 1) UPC2SUPP = UPC2SUPP + LeftHandEncoding(Val(charToEncode), parity2) Return UPC2SUPP Endfunc Function UPC25SUPP() para inpara upc25supp="" For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charPosition = at(charToEncode,"0123456789") If charPosition > 0 Then UPC25SUPP = UPC25SUPP + charToEncode EndIf EndFor strLen = Len(UPC25SUPP) If strLen = 0 Then UPC25SUPP = UPC2SUPP("00") Else If strLen = 1 Then UPC25SUPP = UPC2SUPP(UPC25SUPP + "0") Else If strLen = 2 Then UPC25SUPP = UPC2SUPP(UPC25SUPP) Else If strLen = 3 Then UPC25SUPP = UPC5SUPP(UPC25SUPP + "00") Else If strLen = 4 Then UPC25SUPP = UPC5SUPP(UPC25SUPP + "0") Else If strLen = 5 Then UPC25SUPP = UPC5SUPP(UPC25SUPP) Else UPC25SUPP = UPC5SUPP(Left(UPC25SUPP, 5)) EndIf EndIf EndIf EndIf EndIf EndIf Return UPC25SUPP Endfunc Function getUpcGeneralCheck() para digits checkSum=0 strLen = Len(digits) For i = 1 To strLen If Mod(i,2) = 1 Then checkSum = checkSum + Val(substr(digits, strLen - i + 1, 1)) * 3 Else checkSum = checkSum + Val(substr(digits, strLen - i + 1, 1)) EndIf EndFor getUpcGeneralCheck = mod(checkSum ,10) If getUpcGeneralCheck <> 0 Then getUpcGeneralCheck = 10 - getUpcGeneralCheck EndIf Return int(getUpcGeneralCheck) Endfunc Function textOnly() para onedigit textonly="" do Case Case onedigit="1" textOnly = Chr(193) Case onedigit="2" textOnly = Chr(194) Case onedigit="3" textOnly = Chr(195) Case onedigit="4" textOnly = Chr(196) Case onedigit="5" textOnly = Chr(197) Case onedigit="6" textOnly = Chr(198) Case onedigit="7" textOnly = Chr(199) Case onedigit="8" textOnly = Chr(200) Case onedigit="9" textOnly = Chr(201) Case onedigit="0" textOnly = Chr(192) Endcase Return textonly Endfunc Function convertSetAText() para onedigit do Case Case onedigit="1" convertSetAText = "1" Case onedigit="2" convertSetAText = "2" Case onedigit="3" convertSetAText = "3" Case onedigit="4" convertSetAText = "4" Case onedigit="5" convertSetAText = "5" Case onedigit="6" convertSetAText = "6" Case onedigit="7" convertSetAText = "7" Case onedigit="8" convertSetAText = "8" Case onedigit="9" convertSetAText = "9" Case onedigit="0" convertSetAText = "0" Endcase Return convertsetatext Endfunc Function convertSetBText() para onedigit do Case Case onedigit="1" convertSetBText = "q" Case onedigit="2" convertSetBText = "w" Case onedigit="3" convertSetBText = "e" Case onedigit="4" convertSetBText = "r" Case onedigit="5" convertSetBText = "t" Case onedigit="6" convertSetBText = "y" Case onedigit="7" convertSetBText = "u" Case onedigit="8" convertSetBText = "i" Case onedigit="9" convertSetBText = "o" Case onedigit="0" convertSetBText = "p" Endcase Return convertsetbtext Endfunc Function convertSetCText() para onedigit convertSetCText="" do Case Case onedigit="1" convertSetCText = "a" Case onedigit="2" convertSetCText = "s" Case onedigit="3" convertSetCText = "d" Case onedigit="4" convertSetCText = "f" Case onedigit="5" convertSetCText = "g" Case onedigit="6" convertSetCText = "h" Case onedigit="7" convertSetCText = "j" Case onedigit="8" convertSetCText = "k" Case onedigit="9" convertSetCText = "l" Case onedigit="0" convertSetCText = ";" Endcase Return convertSetCText Endfunc Function convertSetANoText() para onedigit convertSetANoText="" do Case Case onedigit="1" convertSetANoText = "!" Case onedigit="2" convertSetANoText = "@" Case onedigit="3" convertSetANoText= "#" Case onedigit="4" convertSetANoText= "$" Case onedigit="5" convertSetANoText= "%" Case onedigit="6" convertSetANoText= "^" Case onedigit="7" convertSetANoText = "&" Case onedigit="8" convertSetANoText= "*" Case onedigit="9" convertSetANoText="*" Case onedigit="0" convertSetANoText= ")" Endcase Return convertSetANoText Endfunc Function convertSetCNoText() para onedigit convertSetCNoText="" do Case Case onedigit="1" convertSetCNoText= "A" Case onedigit="2" convertSetCNoText = "S" Case onedigit="3" convertSetCNoText= "D" Case onedigit="4" convertSetCNoText= "F" Case onedigit="5" convertSetCNoText= "G" Case onedigit="6" convertSetCNoText= "H" Case onedigit="7" convertSetCNoText= "J" Case onedigit="8" convertSetCNoText= "K" Case onedigit="9" convertSetCNoText="L" Case onedigit="0" convertSetCNoText= ":" Endcase Return convertSetCNoText Endfunc Function code11checksum() para inpara code11checksum=0 strLen = Len(inpara) For i = 1 To Len(inpara) charToEncode = substr(inpara, strLen - i + 1, 1) charPos = at( charToEncode, "0123456789-") If charPos > 0 Then code11checksum = i * (charPos - 1) + code11checksum EndIf EndFor Return code11checksum Endfunc &&---------------------------------------------------------------------*/ &&/* Function: Code39 - applies to Morovia Code39 Fontware */ &&/* Code39(text) Converts the input text into a Code 39 barcode string. The */ &&/* function throws off characters not in the Code 39 character set, */ &&/* and adds start/stop characters. */ &&/*----------------------------------------------------------------------*/ Function Code39() para inpara Code39 = "*" inpara = SpecialChar(inpara) For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charPos = at( charToEncode,"0123456789.+-/ $%ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) If charToEncode = " " Then Code39 = Code39 + "=" else If charPos > 0 Then Code39 = Code39 + charToEncode EndIf EndIf EndFor Code39 = Code39 + "*" Return code39 Endfunc &&----------------------------------------------------------------------------------------*/ &&Converts the input text into a UPC-E barcode. Accepts input of 6 digits of numeric data.*/ &&----------------------------------------------------------------------------------------*/ Function UPC_E() para inpara strSupplement ="" charSet = "0123456789|" inpara = maskfilter(inpara, charSet) charPos = at("|", inpara) If charPos > 0 Then strSupplement = UPC25SUPP(Right(inpara, Len(inpara) - charPos)) inpara = Left(inpara, charPos - 1) EndIf If Len(inpara) < 6 Then do While Len(inpara) < 6 inpara = inpara + "0" enddo Else If Len(inpara) > 6 Then inpara = Left(inpara, 6) EndIf EndIf inpara = "0" + inpara upcaStr = Upce2upca(inpara) checkDigit = getUpcGeneralCheck(upcaStr) do Case Case checkDigit=0 symbmod = "BBBAAA" Case checkDigit=1 symbmod = "BBABAA" Case checkDigit=2 symbmod = "BBAABA" Case checkDigit=3 symbmod = "BBAAAB" Case checkDigit=4 symbmod = "BABBAA" Case checkDigit=5 symbmod = "BAABBA" Case checkDigit=6 symbmod = "BAAABB" Case checkDigit=7 symbmod = "BABABA" Case checkDigit=8 symbmod = "BABAAB" Case checkDigit=9 symbmod = "BAABAB" Endcase UPC_E = "[" For i = 2 To 7 symset = substr(symbmod, i - 1, 1) charToEncode = substr(inpara, i, 1) If symset = "A" Then UPC_E = UPC_E + convertSetAText(charToEncode) Else If symset = "B" Then UPC_E = UPC_E + convertSetBText(charToEncode) EndIf EndIf EndFor UPC_E = textOnly("0") + UPC_E + "'" + textOnly(str(checkDigit,1,0)) If len(alltrim(strSupplement ))> 0 Then UPC_E = UPC_E + " " + strSupplement EndIf Return upc_e Endfunc &&/*----------------------------------------------------------------------------------------*/ &&/*Converts the input text into an EAN barcode. Accepts input of 12 digits of numeric data.*/ &&/*----------------------------------------------------------------------------------------*/ Function EAN13() para inpara strSupplement="" charSet = "0123456789|" inpara = maskfilter(inpara, charSet) charPos = at( "|", inpara) If charPos > 0 Then strSupplement = UPC25SUPP(Right(inpara, Len(inpara) - charPos)) inpara = Left(inpara, charPos - 1) EndIf If Len(inpara) < 12 Then do While Len(inpara) < 12 inpara = inpara + "0" enddo Else If Len(inpara) > 12 Then inpara = Left(inpara, 12) EndIf EndIf getch= substr(inpara, 1, 1) do Case Case getch="0" symbmod = "AAAAAA" Case getch="1" symbmod = "AABABB" Case getch="2" symbmod = "AABBAB" Case getch="3" symbmod = "AABBBA" Case getch="4" symbmod = "ABAABB" Case getch="5" symbmod = "ABBAAB" Case getch="6" symbmod = "ABBBAA" Case getch="7" symbmod = "ABABAB" Case getch="8" symbmod = "ABABBA" Case getch="9" symbmod = "ABBABA" Endcase EAN13 = textOnly(substr(inpara, 1, 1)) + "[" For i = 2 To 7 symPattern = substr(symbmod, i - 1, 1) If symPattern = "A" Then EAN13 = EAN13 + convertSetAText(substr(inpara, i, 1)) Else If symPattern = "B" Then EAN13 = EAN13 + convertSetBText(substr(inpara, i, 1)) EndIf EndIf EndFor EAN13 = EAN13 + "|" For i = 8 To 12 EAN13 = EAN13 + convertSetCText(substr(inpara, i, 1)) EndFor checkDigit = getUpcGeneralCheck(inpara) EAN13 = EAN13 + convertSetCText(str(checkDigit,1,0)) + "]" If len(alltrim(strSupplement)) > 0 Then EAN13 = EAN13 + " " + strSupplement EndIf Return ean13 Endfunc &&----------------------------------------------------------------------------------------*/ &&/*Converts the input text into an EAN-8 barcode. Accepts input of 7 digits of numeric data.*/ &&----------------------------------------------------------------------------------------*/ Function EAN8() para inpara ean8="" strSupplement="" charSet = "0123456789|" inpara = maskfilter(inpara, charSet) charPos = at( "|",inpara) If charPos > 0 Then strSupplement = UPC25SUPP(Right(inpara, Len(inpara) - charPos)) inpara = Left(inpara, charPos - 1) EndIf If Len(inpara) < 7 Then do While Len(inpara) < 7 inpara = inpara + "0" enddo Else If Len(inpara) > 7 Then inpara = Left(inpara, 7) EndIf EndIf For i = 1 To 4 EAN8 = EAN8 + convertSetAText(substr(inpara, i, 1)) EndFor EAN8 = EAN8 + "|" For i = 5 To 7 EAN8 = EAN8 + convertSetCText(substr(inpara, i, 1)) EndFor checkDigit = getUpcGeneralCheck(inpara) EAN8 = "[" + EAN8 + convertSetCText(str(checkDigit,1,0)) + "]" If len(alltrim(strSupplement)) > 0 Then EAN8 = EAN8 + " " + strSupplement EndIf Return ean8 Endfunc &&/*-----------------------------------------------------------------------------*/ &&/*Converts the input text into a Code39 extended symbol. This function */ &&/*should be used to format Morovia code39 font, not Code39 full ASCII font.*/ &&/*The text can be any combinations of ASCII characters. Note that the symbol */ &&/*generated is an extended Code39, and the scanner must be put in Code39 */ &&/*extended mode to read the symbol properly.*/ &&/*----------------------------------------------------------------------------*/ Function Code39Mod43() para inpara checksum=0 code39mod43="" charSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%" mappingSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-.=$/+%" For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charPos = at( charToEncode,charSet) IF charPos>0 then checkSum = checkSum + (charPos - 1) Code39Mod43 = Code39Mod43 + substr(mappingSet, charPos, 1) EndIf EndFor checkSum = mod(checkSum ,43) Code39Mod43 = "*" + Code39Mod43 + substr(mappingSet, checkSum + 1, 1) + "*" Return Code39Mod43 Endfunc &&/*----------------------------------------------------------------------------------------*/ &&/*Converts the input text into a UPC-A barcode. Accepts input of 11 digits of numeric data.*/ &&/*----------------------------------------------------------------------------------------*/ Function UPC_A() para inpara upc_a="" strSupplement="" charSet = "0123456789|" inpara = maskfilter(inpara, charSet) charPos = at("|", inpara) If charPos > 0 Then strSupplement = UPC25SUPP(Right(inpara, Len(inpara) - charPos)) inpara = Left(inpara, charPos - 1) EndIf If Len(inpara) < 11 Then do While Len(inpara) < 11 inpara = inpara + "0" enddo Else If Len(inpara) > 11 Then inpara = Left(inpara, 11) EndIf EndIf sysAssign = substr(inpara, 1, 1) finalString = textOnly(sysAssign) + "[" + convertSetANoText(sysAssign) manuStr = "" For cnter = 1 To 5 manuStr = manuStr + convertSetAText(substr(inpara, (1 + cnter), 1)) EndFor finalString = finalString + manuStr prodStr = "" For cnter = 1 To 5 prodStr = prodStr + convertSetCText(substr(inpara, (6 + cnter), 1)) EndFor finalString = finalString + "|" + prodStr checkDigit = getUpcGeneralCheck(inpara) finalString = finalString + convertSetCNoText(str(checkDigit,1,0)) + "]" + textOnly(str(checkDigit,1,0)) UPC_A = finalString If len(alltrim(strSupplement)) >0 Then UPC_A = UPC_A + " " + strSupplement EndIf strSupplement="" Return upc_a Endfunc &&/*----------------------------------------------------------------------------------------*/ &&/*Converts the input into a valid Code11 symbol. Check digit as well start/stop characters*/ &&/*are added into the input.*/ &&/*----------------------------------------------------------------------------------------*/ Function Code11() para inpara cCheckSum =0 kchecksum =0 code11="" charSet = "0123456789-" Code11 = maskfilter(inpara, charSet) cCheckSum = code11checksum(Code11) cCheckSum = mod(cCheckSum,11) ccheckdigit = substr(charSet, cCheckSum + 1, 1) Code11 = Code11 + ccheckdigit If Len(Code11) > 11 Then kchecksum = code11checksum(Code11) kchecksum = mod(kchecksum , 9) kcheckdigit = Chr(kchecksum + Asc("0")) Code11 = "[" + Code11 + kcheckdigit + "]" Else Code11 = "[" + Code11 + "]" EndIf Return code11 Endfunc Function Code11a() para inpara strStageOne = maskfilter(inpara, "01234567890-") strStageOne = Code11(strStageOne) Code11a = "" For i = 1 To Len(strStageOne) do Case Case substr(strStageOne, i, 1)="[" Code11a = Code11a + substr(strStageOne, i, 1) Case substr(strStageOne, i, 1)=" " Code11a = Code11a + substr(strStageOne, i, 1) Case substr(strStageOne, i, 1)="]" Code11a = Code11a + substr(strStageOne, i, 1) Case substr(strStageOne, i, 1)="-" Code11a = Code11a + "_" Case substr(strStageOne, i, 1)="1" Code11a = Code11a + "!" Case substr(strStageOne, i, 1)="2" Code11a = Code11a + "@" Case substr(strStageOne, i, 1)="3" Code11a = Code11a + "#" Case substr(strStageOne, i, 1)="4" Code11a = Code11a + "$" Case substr(strStageOne, i, 1)="5" Code11a = Code11a + "%" Case substr(strStageOne, i, 1)="6" Code11a = Code11a + "^" Case substr(strStageOne, i, 1)="7" Code11a = Code11a + "&" Case substr(strStageOne, i, 1)="8" Code11a = Code11a + "*" Case substr(strStageOne, i, 1)="9" Code11a = Code11a + "(" Case substr(strStageOne, i, 1)="0" Code11a = Code11a + ")" Endcase EndFor Return Code11a Endfunc &&----------------------------------------------------------------------------------------*/ &&/*Converts the input into a valid Code25 symbol. No check character appended.*/ &&/*----------------------------------------------------------------------------------------*/ Function Code25() para inpara code25="" For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charPos = at(charToEncode, "0123456789") If charPos > 0 Then Code25 = Code25 + charToEncode EndIf EndFor Code25 = "[" + Code25 + "]" Return code25 Endfunc &&/*----------------------------------------------------------------------------------------*/ &&/*Converts the input into a valid Code25 symbol. Append a check digit.*/ &&/*----------------------------------------------------------------------------------------*/ Function code25Check() para inpara checkSum=0 code25Check ="" For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charPos = at( charToEncode,"0123456789") If charPos > 0 Then code25Check = code25Check + charToEncode EndIf EndFor strLen = Len(code25Check) For i = 1 To strLen If Mod(i, 2) = 1 Then checkSum = checkSum + 3 * Val(substr(code25Check, strLen - i + 1, 1)) Else checkSum = checkSum + Val(substr(code25Check, strLen - i + 1, 1)) EndIf EndFor checkSum = mod(checkSum,10) If checkSum = 0 Then checkDigit = "0" Else checkDigit = Chr(10 - checkSum + Asc("0")) EndIf code25Check = "[" + code25Check + checkDigit + "]" Return code25Check Endfunc &&/*----------------------------------------------------------------------------------------*/ &&/*Converts the input into a valid interleaved 2 of 5 barcode. Append a check digit.*/ &&/*----------------------------------------------------------------------------------------*/ Function ITF25Check(inpara ) checkSum=0 ITF25Check="" strTemp="" For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charPos = at( charToEncode,"0123456789") If charPos > 0 Then strTemp = strTemp + charToEncode EndIf EndFor. strLen = Len(strTemp) If mod(strLen,2) = 0 Then strTemp = strTemp + "0" EndIf For i = 1 To strLen If Mod (i,2) = 1 Then checkSum = checkSum + 3 * Val(substr(strTemp, strLen - i + 1, 1)) Else checkSum = checkSum + Val(substr(strTemp, strLen - i + 1, 1)) EndIf EndFor checkSum = mod(checkSum ,10) If checkSum = 0 Then checkDigit = "0" Else checkDigit = Chr(10 - checkSum + Asc("0")) EndIf If mod(Len(strTemp) ,2) = 0 Then strTemp = strTemp + "0" EndIf strTemp = strTemp + checkDigit strLen = Len(strTemp) For i = 1 To strLen Step 2 charToEncode = substr(strTemp, i, 2) charVal = int(Val(charToEncode)) If charVal >= 0 And charVal <= 93 Then ITF25Check = ITF25Check + Chr(Asc("!") + charVal) Else ITF25Check = ITF25Check + Chr(charVal - 94 + 196) EndIf EndFor ITF25Check = Chr(202) + ITF25Check + Chr(203) Return ITF25Check Endfunc &&/*----------------------------------------------------------------------------------------*/ &&/*Converts the input into a valid interleaved 2 of 5 barcode. No check digit appended in */ &&/*this function.*/ &&/*----------------------------------------------------------------------------------------*/ Function ITF25(inpara ) checkSum =0 strTemp="" ITF25="" For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charPos = at(charToEncode, "0123456789") If charPos > 0 Then strTemp = strTemp + charToEncode EndIf EndFor If mod(Len(strTemp),2) = 1 Then strTemp = strTemp + "0" EndIf For i = 1 To Len(strTemp) Step 2 charToEncode = substr(strTemp, i, 2) charVal = Val(charToEncode) If charVal >= 0 And charVal <= 93 Then ITF25 = ITF25 + Chr(Asc("!") + charVal) Else ITF25 = ITF25 + Chr(charVal - 94 + 196) EndIf EndFor ITF25 = Chr(202) + ITF25 + Chr(203) Return itf25 Endfunc &&/*----------------------------------------------------------------------------------------*/ &&/*Converts the input into a valid MSI/Plessey symbol. Check digit is calculated based on */ &&/*Modulo 10 algorithm.*/ &&/*----------------------------------------------------------------------------------------*/ Function MSIMod10(inpara) checkSum=0 MSIMod10="" newno="" For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charPos = at(charToEncode, "0123456789") If charPos > 0 Then MSIMod10 = MSIMod10 + charToEncode EndIf EndFor strLen = Len(MSIMod10) choice = mod(strLen, 2) For i = 1 To strLen charToEncode = substr(MSIMod10, i, 1) charVal = Val(charToEncode) If Mod(i, 2) = choice Then newno = newno + charToEncode Else checkSum = checkSum + charVal EndIf EndFor newno = alltrim(Str(2 * Val(newno),10,0)) For i = 1 To Len(newno) checkSum = checkSum + Val(substr(newno, i, 1)) EndFor checkSum =mod(checkSum ,10) If checkSum <> 0 Then checkSum = 10 - checkSum EndIf MSIMod10 = "[" + MSIMod10 + Chr(Asc("0") + checkSum) + "]" Return MSIMod10 Endfunc Function Code128aCharSet() Code128aCharSet="" For i = 32 To 95 Code128aCharSet = Code128aCharSet + Chr(i) EndFor For i = 0 To 31 Code128aCharSet = Code128aCharSet + Chr(i) EndFor For i = 193 To 199 Code128aCharSet = Code128aCharSet + Chr(i) EndFor Return Code128aCharSet Endfunc Function Code128bCharSet() Code128bCharSet="" For i = 32 To 127 Code128bCharSet = Code128bCharSet + Chr(i) EndFor For i = 193 To 199 Code128bCharSet = Code128bCharSet + Chr(i) EndFor Return Code128bCharSet Endfunc Function Code128cCharset() Code128cCharset="" For i = 0 To 9 Code128cCharset = Code128cCharset + Chr(i + Asc("0")) EndFor For i = 192 To 199 Code128cCharset = Code128cCharset + Chr(i) EndFor Return Code128cCharset Endfunc Function code128MappingSet() code128MappingSet = Chr(204) For i = 33 To 126 code128MappingSet = code128MappingSet + Chr(i) EndFor For i = 192 To 202 code128MappingSet = code128MappingSet + Chr(i) EndFor Return code128MappingSet Endfunc &&/*----------------------------------------------------------------------------------------*/ &&/*Encode any ASCII characters. It automatically shift to another character set when the */ &&/*encoded character is not found in the current character set.*/ &&/*----------------------------------------------------------------------------------------*/ Function code128Auto(inpara ) checkSum =0 AcharSet = Code128aCharSet() BcharSet = Code128bCharSet() CcharSet = Code128cCharset() mappingSet = code128MappingSet() curCharSet="" inpara = SpecialChar(inpara) code128Auto = "" If len(alltrim(inpara)) = 0 Then code128Auto = "" Return 0 EndIf strLen = Len(inpara) charVal = Asc(substr(inpara, 1, 1)) If charVal <= 31 Then curCharSet = AcharSet EndIf If charVal >= 32 And charVal <= 126 Then curCharSet = BcharSet EndIf If (strLen > 4) And Isdigit(substr(inpara, 1, 1)) And Isdigit(substr(inpara, 2, 1)) And Isdigit(substr(inpara, 3, 1)) And Isdigit(substr(inpara, 4, 1) ) Then curCharSet = CcharSet EndIf do Case Case curCharSet=AcharSet code128Auto = code128Auto + Chr(200) Case curCharSet=BcharSet code128Auto = code128Auto + Chr(201) Case curCharSet=CcharSet code128Auto = code128Auto + Chr(202) Endcase For i = 1 To strLen charToEncode = substr(inpara, i, 1) charVal = Asc(charToEncode) If charVal = 199 Then code128Auto = code128Auto + Chr(199) Else If ((i < strLen - 2) And (isdigit(charToEncode)) And (isdigit(substr(inpara, i + 1, 1))) And (isdigit(substr(inpara, i, 4)))) Or ((i < strLen) And (isdigit(charToEncode)) And (isdigit(substr(inpara, i + 1, 1))) And (curCharSet = CcharSet)) Then If curCharSet <> CcharSet Then code128Auto = code128Auto + Chr(196) curCharSet = CcharSet EndIf charToEncode = substr(inpara, i, 2) charVal = Val(charToEncode) code128Auto = code128Auto + substr(mappingSet, charVal + 1, 1) i = i + 1 Else If (((i <= strLen) And (charVal < 31)) Or ((curCharSet = AcharSet) And (charVal > 32 And charVal < 96))) Then If curCharSet <> AcharSet Then code128Auto = code128Auto + Chr(198) curCharSet = AcharSet EndIf charPos = at( charToEncode, curCharSet) code128Auto = code128Auto + substr(mappingSet, charPos, 1) Else If (i <= strLen) And (charVal > 31 And charVal < 127) Then If curCharSet <> BcharSet Then code128Auto = code128Auto + Chr(197) curCharSet = BcharSet EndIf charPos = at( charToEncode, curCharSet) code128Auto = code128Auto + substr(mappingSet, charPos, 1) EndIf EndIf EndIf EndIf EndFor strLen = Len(code128Auto) For i = 1 To strLen charVal = (Asc(substr(code128Auto, i, 1))) If charVal = 204 Then charVal = 0 Else If charVal <= 126 Then charVal = charVal - 32 Else If charVal >= 192 Then charVal = charVal - 97 EndIf EndIf EndIf If i > 1 Then weight = i - 1 Else weight = 1 EndIf checkSum = checkSum + charVal * weight EndFor checkSum = mod(checkSum,103) checkDigit = substr(mappingSet, checkSum + 1, 1) code128Auto = code128Auto + checkDigit + Chr(203) + Chr(205) Return code128Auto Endfunc &&/*----------------------------------------------------------------------------------------*/ &&/*Accepts the input of character set A. Code128 character set consists of capital letters */ &&/*and control characters.*/ &&/*----------------------------------------------------------------------------------------*/ Function Code128A(inpara ) checkSum=0 Code128A="" strTemp="" AcharSet = Code128aCharSet() mappingSet = code128MappingSet() inpara = SpecialChar(inpara) For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charPos = at(charToEncode,AcharSet) If charPos > 0 Then strTemp = strTemp + charToEncode EndIf EndFor checkSum = 103 For i = 1 To Len(strTemp) charToEncode =substr(strTemp, i, 1) charPos = at( charToEncode,AcharSet) If charPos > 0 Then Code128A = Code128A + substr(mappingSet, charPos, 1) checkSum = checkSum + i * (charPos - 1) EndIf EndFor checkSum = mod(checkSum,103) checkDigit = substr(mappingSet, checkSum + 1, 1) Code128A = Chr(200) + Code128A + checkDigit + Chr(203) + Chr(205) Return Code128A Endfunc &&/*----------------------------------------------------------------------------------------*/ &&/*Accepts the input of character set B. Code128 character set consist of all printable */ &&/*characters in the ASCII table.*/ &&/*----------------------------------------------------------------------------------------*/ Function Code128B(inpara ) checkSum=0 Code128B="" strTemp="" BcharSet = Code128bCharSet() mappingSet = code128MappingSet() inpara = SpecialChar(inpara) For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charPos = at( charToEncode,BcharSet) If charPos > 0 Then strTemp = strTemp + charToEncode EndIf EndFor checkSum = 104 For i = 1 To Len(strTemp) charToEncode = substr(strTemp, i, 1) charPos = at( charToEncode, BcharSet) If charPos > 0 Then Code128B = Code128B + substr(mappingSet, charPos, 1) checkSum = checkSum + i * (charPos - 1) EndIf EndFor checkSum = mod(checkSum ,103) checkDigit = substr(mappingSet, checkSum + 1, 1) Code128B = Chr(201) + Code128B + checkDigit + Chr(203) + Chr(205) Return code128b Endfunc &&/*----------------------------------------------------------------------------------------*/ &&/*Code128 character set C only contains numeric characters. Used when the encoded data */ &&/*containing only numbers.*/ &&/*----------------------------------------------------------------------------------------*/ Function Code128C(inpara ) checkSum=0 strTemp="" Code128C="" CcharSet = Code128cCharset() mappingSet = code128MappingSet() inpara = SpecialChar(inpara) For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charPos = at(charToEncode, CcharSet) If charPos > 0 Then strTemp = strTemp + charToEncode EndIf EndFor If mod(Len(strTemp) , 2) = 1 Then strTemp = strTemp + "0" EndIf checkSum = 105 For i = 1 To Len(strTemp) Step 2 charToEncode = substr(strTemp, i, 2) charVal = Val(charToEncode) Code128C = Code128C + substr(mappingSet, charVal + 1, 1) EndFor For i = 1 To Len(Code128C) charToEncode = substr(Code128C, i, 1) charVal = Asc(charToEncode) If charVal = 204 Then charVal = 0 Else If charVal >= 33 And charVal < 127 Then checkSum = checkSum + i * (charVal - 32) Else checkSum = checkSum + i * (charVal - 97) EndIf EndIf EndFor checkSum = mod(checkSum ,103) checkDigit = substr(mappingSet, checkSum + 1, 1) Code128C = Chr(202) + Code128C + checkDigit + Chr(203) + Chr(205) Return code128c Endfunc &&/*-------------------------------------------------------------------------------*/ &&/*Converts the input text into a Code93 symbol. It accepts any ASCII character input,*/ &&/*taking care of the check character calculation and adding start/stop characters into*/ &&/*the string.*/ &&/*------------------------------------------------------------------------------------*/ Function Code93(inpara ) checkSumC=0 checkSumK=0 strTemp="" code93="" charSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%@#^&" mappingSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-.=$/+%@#^&" inpara = SpecialChar(inpara) For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) If Asc(charToEncode) = 0 Then strTemp = strTemp + "#" + "U" Else If Asc(charToEncode) >= 1 And Asc(charToEncode) <= 26 Then strTemp = strTemp + "@" + Chr(Asc(charToEncode) + Asc("A") - 1) Else If Asc(charToEncode) >= 27 And Asc(charToEncode) <= 31 Then strTemp = strTemp + "#" + Chr(Asc(charToEncode) - 27 + Asc("A")) Else If Asc(charToEncode) = 32 Then strTemp = strTemp + "=" Else If Asc(charToEncode) >= 33 And Asc(charToEncode) <= 44 Then strTemp = strTemp + "^" + Chr(Asc(charToEncode) - 33 + Asc("A")) Else If charToEncode = "-" Then strTemp = strTemp + charToEncode Else If charToEncode = "." Then strTemp = strTemp + charToEncode Else If charToEncode = "/" Then strTemp = strTemp + "^" + "O" Else If Asc(charToEncode) >= 48 And Asc(charToEncode) <= 57 Then strTemp = strTemp + charToEncode Else If charToEncode = ":" Then strTemp = strTemp + "^" + "Z" Else If Asc(charToEncode) >= 59 And Asc(charToEncode) <= 63 Then strTemp = strTemp + "#" + Chr(Asc(charToEncode) - 59 + Asc("F")) Else If Asc(charToEncode) = 64 Then strTemp = strTemp + "#" + "V" Else If Asc(charToEncode) >= 65 And Asc(charToEncode) <= 90 Then strTemp = strTemp + charToEncode Else If Asc(charToEncode) >= 91 And Asc(charToEncode) <= 95 Then strTemp = strTemp + "#" + Chr(Asc(charToEncode) - 91 + Asc("K")) Else If Asc(charToEncode) = 96 Then strTemp = strTemp + "#" + "W" Else If Asc(charToEncode) >= 97 And Asc(charToEncode) <= 122 Then strTemp = strTemp + "&" + Chr(Asc(charToEncode) - 97 + Asc("A")) Else If Asc(charToEncode) >= 123 And Asc(charToEncode) <= 127 Then strTemp = strTemp + "#" + Chr(Asc(charToEncode) - 123 + Asc("P")) EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndFor Code93 = strTemp For i = 1 To Len(Code93) weightC =Mod(i, 20) &&Added by Ben May 12,2004 if weightC=0 then weightC=20; charToEncode = substr(Code93, Len(Code93) - i + 1, 1) charPos = at( charToEncode,mappingSet) checkSumC = checkSumC + weightC * (charPos - 1) EndFor Code93 = Code93 + substr(mappingSet, mod(checkSumC,47) + 1, 1) For i = 1 To Len(Code93) weightK = Mod(i, 15) &&Added by Ben May 12,2004 if weightK=0 then weightK=15; charToEncode = substr(Code93, Len(Code93) - i + 1, 1) charPos = at( charToEncode, mappingSet) checkSumK = checkSumK + weightK * (charPos - 1) EndFor Code93 = Code93 + substr(mappingSet, mod(checkSumK, 47) + 1, 1) Code93 = "[" + Code93 + "]" + "|" Return code93 Endfunc &&/*----------------------------------------------------------------------------------------*/ &&/*Converts the input into a valid Codabar symbol. The default start/stop characters are “A?/ &&/*and “B?*/ &&/*----------------------------------------------------------------------------------------*/ Function Codabar(inpara ) codabar="" charSet = "0123456789-$:/.+" For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charPos = at(charToEncode, charSet) If charPos > 0 Then Codabar = Codabar + charToEncode EndIf EndFor Codabar = "A" + Codabar + "B" Return codabar Endfunc &&/*-------------------------------------------------------------------------------*/ &&/*Converts the input text into a Code39 extended symbol. This function should be */ &&/*used to format Morovia code39 font, not Code39 full ASCII font. The text can be*/ &&/*any combinations of ASCII characters. Note that the symbol generated is an extended*/ &&/*Code39, and the scanner must be put in Code39 extended mode to read the symbol properly.*/ &&/*-----------------------------------------------------------------------------------------*/ Function Code39Ascii(inpara) strTemp="" code39Ascii="" inpara = SpecialChar(inpara) For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) If Asc(charToEncode) = 0 Then strTemp = strTemp + "%U" Else If Asc(charToEncode) >= 1 And Asc(charToEncode) <= 26 Then strTemp = strTemp + "$" + Chr(Asc(charToEncode) + Asc("A") - 1) Else If Asc(charToEncode) >= 27 And Asc(charToEncode) <= 31 Then strTemp = strTemp + "%" + Chr(Asc(charToEncode) - 27 + Asc("A")) Else If Asc(charToEncode) = 32 Then strTemp = strTemp + "=" Else If Asc(charToEncode) >= 33 And Asc(charToEncode) <= 44 Then strTemp = strTemp + "/" + Chr(Asc(charToEncode) - 33 + Asc("A")) Else If charToEncode = "-" Then strTemp = strTemp + charToEncode Else If charToEncode = "." Then strTemp = strTemp + charToEncode Else If charToEncode = "/" Then strTemp = strTemp + "/O" Else If Asc(charToEncode) >= 48 And Asc(charToEncode) <= 57 Then strTemp = strTemp + charToEncode Else If charToEncode = ":" Then strTemp = strTemp + "/Z" Else If Asc(charToEncode) >= 59 And Asc(charToEncode) <= 63 Then strTemp = strTemp + "%" + Chr(Asc(charToEncode) - 59 + Asc("F")) Else If Asc(charToEncode) = 64 Then strTemp = strTemp + "%V" Else If Asc(charToEncode) >= 65 And Asc(charToEncode) <= 90 Then strTemp = strTemp + charToEncode Else If Asc(charToEncode) >= 91 And Asc(charToEncode) <= 95 Then strTemp = strTemp + "%" + Chr(Asc(charToEncode) - 91 + Asc("K")) Else If Asc(charToEncode) = 96 Then strTemp = strTemp + "%W" Else If Asc(charToEncode) >= 97 And Asc(charToEncode) <= 122 Then strTemp = strTemp + "+" + Chr(Asc(charToEncode) - 97 + Asc("A")) Else If Asc(charToEncode) >= 123 And Asc(charToEncode) <= 127 Then strTemp = strTemp + "%" + Chr(Asc(charToEncode) - 123 + Asc("P")) EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndFor Code39Ascii = "[" + strTemp + "]" Return code39ascii Endfunc &&/*-------------------------------------------------------------------------------*/ &&/*Converts the input text into a Code39 extended symbol. It accepts any ASCII */ &&/*characters as input. The only difference from function Code39Ascii is the former */ &&/*is designed to work with Morovia Code39(Full ASCII) font and the latter is designed*/ &&/*to work with Morovia Code39 font.*/ &&/*-----------------------------------------------------------------------------------*/ Function Code39Extended(inpara ) Code39Extended="" inpara = SpecialChar(inpara) For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charVal = Asc(charToEncode) If charToEncode = " " Then Code39Extended = Code39Extended + "=" Else If charToEncode = "*" Then Code39Extended = Code39Extended + Chr(244) Else If charToEncode = "=" Then Code39Extended = Code39Extended + Chr(240) Else If charToEncode = "[" Then Code39Extended = Code39Extended + Chr(241) Else If charToEncode = "]" Then Code39Extended = Code39Extended + Chr(242) Else If charVal = 127 Then Code39Extended = Code39Extended + Chr(224) Else If charVal >= 0 And charVal <= 31 Then Code39Extended = Code39Extended + Chr(192 + charVal) Else Code39Extended = Code39Extended + charToEncode EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndFor Code39Extended = "*" + Code39Extended + "*" Return Code39Extended Endfunc &&/*--------------------------------------------------------*/ &&/*Converts an ISBN string into a valid Bookland barcode. */ &&/*--------------------------------------------------------*/ Function Bookland(inpara) Bookland="" strRight="" charPos = at( "|", inpara) If charPos > 0 Then strLeft = Left(inpara, charPos - 1) strRight = substr(inpara, charPos + 1, Len(inpara) - charPos) Else strLeft = inpara EndIf charSet = "0123456789" strLeft = maskfilter(strLeft, charSet) strRight = maskfilter(strRight, charSet) If Len(strLeft) > 10 Then strLeft = Left(strLeft, 10) Else If Len(inpara) < 10 Then do While Len(strLeft) < 10 strLeft = strLeft + "0" enddo EndIf EndIf strLeft = "978" + Left(strLeft, 9) Bookland = EAN13(strLeft) If charPos > 0 Then Bookland = Bookland + " " + UPC25SUPP(strRight) EndIf Return bookland Endfunc Function codeISBN(inpara ) checkSum=0 codeISBN="" charSet = "0123456789" inpara = maskfilter(inpara, charSet) If Len(inpara) > 9 Then inpara = Left(inpara, 9) Else If Len(inpara) < 9 Then do while Len(inpara) < 9 inpara = inpara + "0" enddo EndIf EndIf codeISBN = inpara For i = 1 To Len(codeISBN) weight = 11 - i charToEncode = substr(codeISBN, i, 1) checkSum = checkSum + weight * Val(charToEncode) EndFor checkSum = 11 - (mod(checkSum,11)) checkDigit = Chr(checkSum + Asc("0")) codeISBN = codeISBN + checkDigit Return codeISBN Endfunc Function EAN128(inpara) EAN128="" strTemp="" strCodeWord="" checkSum=0 mappingSet = code128MappingSet() inpara = SpecialChar(inpara) strLen = Len(inpara) For i = 1 To strLen If substr(inpara, i, 1) = Chr(199) Then strTemp = strTemp + Chr(199) Else If Isdigit(substr(inpara, i, 1)) Then If i + 1 <= strLen And Isdigit(substr(inpara, i + 1, 1)) Then strTemp = strTemp + substr(inpara, i, 2) i = i + 1 Else strTemp = strTemp + substr(inpara, i, 1) + "0" EndIf EndIf EndIf EndFor strLen = Len(strTemp) checkSum = 105 + 102 weight = 2 For i = 1 To strLen charToEncode = substr(strTemp, i, 1) If charToEncode <> Chr(199) Then charValue = Val(substr(strTemp, i, 2)) strCodeWord = strCodeWord + substr(mappingSet, charValue + 1, 1) charValue = charValue * weight i = i + 1 Else strCodeWord = strCodeWord + Chr(199) charValue = 102 * weight EndIf checkSum = checkSum + charValue weight = weight + 1 EndFor checkSum = mod(checkSum,103) checkDigit = substr(mappingSet, checkSum + 1, 1) EAN128 = Chr(202) + Chr(199) + strCodeWord + checkDigit + Chr(203) + Chr(205) Return ean128 Endfunc Function SCC14(inpara) strTemp="" checkSum=0 scc14="" strLen = Len(inpara) For i = 1 To strLen charToEncode = substr(inpara, i, 1) If charToEncode >= "0" And charToEncode <= "9" Then strTemp = strTemp + charToEncode EndIf EndFor If Len(strTemp) = 14 Then strTemp = substr(strTemp, 1, 13) EndIf If Len(strTemp) = 15 Or Len(strTemp) = 16 Or Len(strTemp) = 17 Then strTemp = substr(strTemp, 3, 13) EndIf If Len(strTemp) <> 13 Then Return 0 EndIf strLen = Len(strTemp) For i = 1 To strLen charValue = Val(substr(strTemp, strLen - i + 1, 1)) If Mod(i,2) = 1 Then weight = 3 Else weight = 1 EndIf checkSum = checkSum + charValue * weight EndFor checkSum = mod(checkSum,10) If checkSum = 0 Then checkDigit = "0" Else checkDigit = Chr(10 - checkSum + Asc("0")) EndIf SCC14 = EAN128("01" + strTemp + checkDigit) Return scc14 Endfunc function SSCC18(inpara ) checkSum =0 sscc18="" strTemp="" inpara = SpecialChar(inpara) strLen = Len(inpara) For i = 1 To strLen charToEncode = substr(inpara, i, 1) If charToEncode >= "0" And charToEncode <= "9" Then strTemp = strTemp + charToEncode EndIf EndFor If Len(strTemp) = 18 Then strTemp = substr(strTemp, 1, 17) EndIf If Len(strTemp) = 19 Or Len(strTemp) = 20 Or Len(strTemp) = 21 Then strTemp = substr(strTemp, 3, 17) EndIf If Len(strTemp) <> 17 Then Return 0 EndIf strLen = Len(strTemp) For i = 1 To strLen charValue = Val(substr(strTemp, strLen - i + 1, 1)) If Mod(i, 2) = 1 Then weight = 3 Else weight = 1 EndIf checkSum = checkSum + charValue * weight EndFor checkSum = mod(checkSum ,10) If checkSum = 0 Then checkDigit = "0" Else checkDigit = Chr(10 - checkSum + Asc("0")) EndIf SSCC18 = EAN128("00" + strTemp + checkDigit) Return sscc18 Endfunc &&/*----------------------------------------------------------------------------------------*/ &&/*Used for 22 digit USPS special services labels such as delivery confirmation in EAN128. */ &&/*This function takes 19 digit input which is made up of the three parts: 2 digit service */ &&/*code, 9 digit customer ID and 8 digit sequential package ID. This function calculates the*/ &&/*check digit (Mod10), add the application identifier 91 as required by the USPS standard,*/ &&/*and format the data with EAN128 standard. */ &&/*----------------------------------------------------------------------------------------*/ Function USPS_EAN128(inpara) strTemp="" checkSum=0 USPS_EAN128="" inpara = SpecialChar(inpara) strLen = Len(inpara) For i = 1 To strLen charToEncode = substr(inpara, i, 1) If charToEncode >= "0" And charToEncode <= "9" Then strTemp = strTemp + charToEncode EndIf EndFor If Len(strTemp) > 19 Then strTemp = substr(strTemp, 1, 19) EndIf If Len(strTemp) <> 19 Then strTemp = "0000000000000000000" EndIf strTemp = "91" + strTemp strLen = Len(strTemp) For i = 1 To strLen charValue = Val(substr(strTemp, strLen - i + 1, 1)) If Mod(i,2) = 1 Then weight = 3 Else weight = 1 EndIf checkSum = checkSum + charValue * weight EndFor checkSum = mod(checkSum,10) If checkSum = 0 Then checkDigit = "0" Else checkDigit = Chr(10 - checkSum + Asc("0")) EndIf USPS_EAN128 = EAN128(strTemp + checkDigit) Return USPS_EAN128 Endfunc Function USPS_USS128(inpara ) strTemp="" checkSum=0 USPS_USS128="" inpara = SpecialChar(inpara) strLen = Len(inpara) For i = 1 To strLen charToEncode =substr(inpara, i, 1) If charToEncode >= "0" And charToEncode <= "9" Then strTemp = strTemp + charToEncode EndIf EndFor If Len(strTemp) = 20 Then strTemp = substr(strTemp, 1, 19) EndIf If Len(strTemp) <> 19 Then Return 0 EndIf strLen = Len(strTemp) For i = 1 To strLen charValue = Val(substr(strTemp, strLen - i + 1, 1)) If Mod(i, 2) = 1 Then weight = 3 Else weight = 1 EndIf checkSum = checkSum + charValue * weight EndFor checkSum =mod(checkSum ,10) If checkSum = 0 Then checkDigit = "0" Else checkDigit = Chr(10 - checkSum + Asc("0")) EndIf USPS_USS128 = EAN128(strTemp + checkDigit) Return USPS_USS128 Endfunc &&/*----------------------------------------------------------------------------*/ &&/*Converts the input into a valid UK royal mail barcode symbol with checksum. */ &&/*The function adds the start/stop frame bar, calculating the check digit and */ &&/*forms the correct symbol.*/ &&/*----------------------------------------------------------------------------*/ Function RoyalMail(inpara ) checkSum =0 RoyalMail="" tu=0 tl=0 charSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) charPos = at(charToEncode, charSet) If (charPos > 0) Then RoyalMail = RoyalMail + charToEncode charVal = Asc(charToEncode) If (charVal < 65) Then charVal = charVal - 48 Else charVal = charVal - 55 EndIf temp = Int(charVal / 6) If (temp >= 5) Then checkSum = 0 Else checkSum = temp + 1 EndIf tu = tu + checkSum temp = Int(charVal - temp * 6) If temp >= 5 Then checkSum = 0 Else checkSum = temp + 1 EndIf tl = tl + checkSum EndIf EndFor tu = Mod(tu, 6) If tu = 0 Then tu = 6 EndIf tl = Mod(tl, 6) If tl = 0 Then tl = 6 EndIf checkSum = (tu - 1) * 6 + tl - 1 If checkSum < 10 Then checkDigit = Chr(checkSum + 48) Else checkDigit = Chr(checkSum + 55) EndIf RoyalMail = "[" + RoyalMail + checkDigit + "]" Return royalmail Endfunc &&/*-----------------------------------------------------------------------*/ &&/*Converts the input into a valid POSTNET barcode string with checksum.*/ &&/*The function adds the start/stop frame bar, calculating the check digit*/ &&/*and forms the correct symbol. This function can also be used to generate*/ &&/*PLANET barcode string.*/ &&/*-----------------------------------------------------------------------*/ function Postnet(inpara ) checkSum =0 postnet="" charSet = "0123456789" inpara = maskfilter(inpara, charSet) If Len(inpara) >= 0 And Len(inpara) < 5 Then do While Len(inpara) < 5 inpara = inpara + "0" enddo Else If Len(inpara) > 5 And Len(inpara) < 9 Then do While Len(inpara) < 9 inpara = inpara + "0" enddo Else If Len(inpara) > 9 And Len(inpara) < 13 Then do While Len(inpara) < 13 inpara = inpara + "0" enddo Else If Len(inpara) > 13 Then inpara = Left(inpara, 13) EndIf EndIf EndIf EndIf For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) If Isdigit(charToEncode) Then Postnet = Postnet + charToEncode checkSum = checkSum + Val(charToEncode) EndIf EndFor checkSum = mod(checkSum,10) If checkSum <> 0 Then checkSum = 10 - checkSum EndIf checkDigit = Chr(checkSum + Asc("0")) Postnet = "[" + Postnet + checkDigit + "]" Return postnet Endfunc &&/*----------------------------------------------------------------------------*/ &&/*Converts the input into a Telepen barcode string. The function accepts any */ &&/*ASCII character input, taking care of the check digit calculation and adding*/ &&/*start/stop characters.*/ &&/*----------------------------------------------------------------------------*/ Function telepen(inpara) strTemp="" checkSum =0 telepen="" inpara = SpecialChar(inpara) For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) If (Asc(charToEncode) >= 0 And Asc(charToEncode) <= 127) Then strTemp = strTemp + charToEncode checkSum = checkSum + Asc(charToEncode) EndIf EndFor checkDigit = Chr(127 - (mod(checkSum ,127))) strTemp = strTemp + checkDigit For i = 1 To Len(strTemp) charToEncode = substr(strTemp, i, 1) If (charToEncode = " ") Then telepen = telepen + "=" Else If (charToEncode = "=") Then telepen = telepen + Chr(240) Else If (charToEncode = "[") Then telepen = telepen + Chr(241) Else If (charToEncode = "]") Then telepen = telepen + Chr(242) Else If (Asc(charToEncode) >= 0 And Asc(charToEncode) <= 31) Then telepen = telepen + Chr(Asc(charToEncode) + 192) Else If (Asc(charToEncode) = 127) Then telepen = telepen + Chr(224) Else telepen = telepen + charToEncode EndIf EndIf EndIf EndIf EndIf EndIf EndFor telepen = "[" + telepen + "]" Return telepen Endfunc &&/*----------------------------------------------------------------------------*/ &&/*Converts the input into a Telepen Numeric barcode string. This functions */ &&/*accepts numeric input only.*/ &&/*----------------------------------------------------------------------------*/ Function telepenNumeric(inpara) checkSum=0 strTemp ="" telepenNumeric="" mappingSet="" For i = 1 To Len(inpara) charToEncode = substr(inpara, i, 1) If charToEncode >= "0" And charToEncode <= "9" Then strTemp = strTemp + charToEncode EndIf EndFor If mod(Len(strTemp), 2) = 1 Then strTemp = strTemp + "0" EndIf For i = 1 To Len(strTemp) Step 2 charToEncode = substr(strTemp, i, 2) charVal = Val(charToEncode) + 27 mappingSet = mappingSet + Chr(charVal) EndFor For i = 1 To Len(mappingSet) charToEncode = substr(mappingSet, i, 1) charVal = Asc(charToEncode) checkSum = checkSum + charVal EndFor checkDigit = Chr(127 - (mod(checkSum,127))) mappingSet = mappingSet + checkDigit For i = 1 To Len(mappingSet) charToEncode = substr(mappingSet, i, 1) If (charToEncode = " ") Then telepenNumeric = telepenNumeric + "=" Else If (charToEncode = "=") Then telepenNumeric = telepenNumeric + Chr(240) Else If (charToEncode = "[") Then telepenNumeric = telepenNumeric + Chr(241) Else If (charToEncode = "]") Then telepenNumeric = telepenNumeric + Chr(242) Else If (Asc(charToEncode) >= 0 And Asc(charToEncode) <= 31) Then telepenNumeric = telepenNumeric + Chr(Asc(charToEncode) + 192) Else If (Asc(charToEncode) = 127) Then telepenNumeric = telepenNumeric + Chr(224) Else telepenNumeric = telepenNumeric + charToEncode EndIf EndIf EndIf EndIf EndIf EndIf EndFor telepenNumeric = "[" + telepenNumeric + "]" Return telepenNumeric Endfunc