You are on page 1of 3

$PBExportHeader$f_getbarcode128.

srf global type f_getbarcode128 from function_object end type forward prototypes global function string f_getbarcode128 (string chaine) end prototypes global function string f_getbarcode128 (string chaine); //Cette fonction est rgie par la Licence Gnrale Publique Amoindrie GNU (GNU LGPL) //This function is governed by the GNU Lesser General Public License (GNU LGPL ) //V 2.0.0 //Paramtres : une chaine //Parameters : a string //Retour : * une chaine qui, affiche avec la police CODE128.TTF, donne le code barre // * une chaine vide si paramtre fourni incorrect //Return : * a string which give the bar code when it is dispayed with CODE128 .TTF font // * an empty string if the supplied parameter is no good long i, checksum, mini, dummy boolean tableB string code128 = "" If Len(chaine) > 0 Then //Vrifier si caractres valides //Check for valid characters For i = 1 To Len(chaine) if Asc(Mid(chaine, i, 1)) = 32 AND Asc(Mid(chaine, i, 1)) = 126 Then Else i = 0 Exit End if Next //Calculer la chaine de code en optimisant l//usage des tables B et C //Calculation of the code string with optimized use of tables B and C code128 = "" tableB = True // If i > 0 Then i = 1 //i% devient l//index sur la chaine / i% become the string index Do While i <= Len(chaine) If tableB Then //Voir si intressant de passer en table C / See if interesting to switc h to table C //Oui pour 4 chiffres au dbut ou la fin, sinon pour 6 chiffres / yes fo r 4 digits at start or end, else if 6 digits If (i = 1 Or (i + 3 = Len(chaine))) then mini = 4 else mini = 6 end if //testnum mini = mini - 1 If i + mini <= Len(chaine) Then Do While mini >= 0 If Asc(Mid(chaine, i + mini, 1)) < 48 Or Asc(Mid(chaine, i + min i, 1)) > 57 Then Exit mini = mini - 1 Loop

End If //fine testnum If mini < 0 Then //Choix table C / Choice of table C If i = 1 Then //Dbuter sur table C / Starting with table C code128 = CharA(210) Else //Commuter sur table C / Switch to table C code128 = code128 + CharA(204) End If tableB = False Else If i = 1 Then code128 = CharA(209) //Dbuter sur table B / Starting wi th table B End If End If If Not tableB Then //On est sur la table C, essayer de traiter 2 chiffres / We are on tab le C, try to process 2 digits mini = 2 //testnum mini = mini - 1 If i + mini <= Len(chaine) Then Do While mini >= 0 If Asc(Mid(chaine, i + mini, 1)) < 48 Or Asc(Mid(chaine, i + min i, 1)) > 57 Then Exit mini = mini - 1 Loop End If //fine testnum If mini < 0 Then //OK pour 2 chiffres, les traiter / OK for 2 digits, process it dummy = long((Mid(chaine, i, 2))) If(dummy < 95) then dummy=dummy + 32 else dummy=dummy + 105 end if code128 = code128 + chara(dummy) i = i + 2 Else //On n//a pas 2 chiffres, repasser en table B / We haven//t 2 dig its, switch to table B code128 = code128 + chara(205) tableB = True End If End If If tableB Then //Traiter 1 caractre en table B / Process 1 digit with table B code128 = code128 + Mid(chaine, i, 1) i = i + 1 End If Loop //Calcul de la cl de contrle / Calculation of the checksum For i = 1 To Len(code128) dummy = Asc(Mid(code128, i, 1)) if dummy < 127 then dummy= dummy - 32 else dummy=dummy - 105 end if

If i = 1 Then checksum = dummy checksum = mod((checksum + (i - 1) * dummy), 103) Next //Calcul du code ASCII de la cl / Calculation of the checksum ASCII code If(checksum < 95) then checksum=checksum + 32 else checksum=checksum + 105 end if //Ajout de la cl et du STOP / Add the checksum and the STOP code128 = code128 + Chara(checksum) + Chara(211) End If // End If return code128 end function

You might also like