* FoxPro encoder function for Interleaved 2/5 barcode * Copyright by MW6 Technologies Inc. All rights reserved. * * This code may not be modified or distributed unless you purchase * the license from MW6. * Rename this file to MW6IT25.PRG, add MW6IT25.PRG to your VFP project, * put the following command in VFP code: * SET PROCEDURE TO MW6IT25.PRG ADDITIVE * * Sample code * private res * res = IT25("1234567890", .T.) * res = IT25("123456", .F.) Function IT25 * The parameter "CheckDigit" is used to specify whether the check-digit * will be added to barcode or not. lparameters Src, CheckDigit private I, Tmp, StrLen, EncodedMessage, CheckSum, Weight, V StrLen = Len(Src) If (CheckDigit) Then CheckSum = 0 Weight = 3 For I = 1 To StrLen CurrChar = Asc(SubStr(Src, StrLen + 1 - I, 1)) - Asc("0") CheckSum = CheckSum + CurrChar * Weight Weight = 4 - Weight Next I CheckSum = Mod(CheckSum, 10) If (CheckSum <> 0) Then CheckSum = 10 - CheckSum EndIf Tmp = Src + Chr(CheckSum + Asc("0")) If (Mod(Len(Tmp), 2) = 1) Then Tmp = "0" + Tmp EndIf Else If (Mod(StrLen, 2) = 1) Then Tmp = "0" + Src Else Tmp = Src EndIf EndIf StrLen = Len(Tmp) * start character (198) EncodedMessage = Chr(198) I = 1 Do While (I < StrLen) V = Asc(SubStr(Tmp, I, 1)) - Asc("0") V = 10 * V + Asc(SubStr(Tmp, I + 1, 1)) - Asc("0") If (V < 94) Then EncodedMessage = EncodedMessage + Chr(V + 33) Else EncodedMessage = EncodedMessage + Chr(V + 98) EndIf I = I + 2 EndDo While * stop character (199) EncodedMessage = EncodedMessage + Chr(199) return EncodedMessage EndFunc