เนื่องจากต้องเขียนโปรแกรมเกี่ยวกับเครื่อง Scan Barcode และ Barcode มีหลายแบบ แบบง่ายสุดก็จะเป็น Fonts Barcode ซึ่งสามารถนำไปใช้ได้เลยไม่ต้องยุ่งยาก มาก แต่ถ้าต้องเขียน Barcode EAN13 ซึ่งมีการเข้ารหัส ดัวย ทำให้ต้องหาข้อมูลในเว็บ ซึ่งไปเจอ เว็บ http://grandzebu.net/informatique/codbar-en/ean13.htm ซึ่งในเว็บจะอธิบายเกี่ยวกับ Code EAN13 ไว้อย่างละเอียด และมี Code โปรแกรมสำหรับ พิมพ์ Barcode แบบ EAN13 ออกมาใช้ได้เลย ด้วย
Code VB6 สามารถนำไปใช้ใน VBA Macro ใน Word Excel
Public Function ean13$(chaine$) 'Cette fonction est regie par la Licence Generale Publique Amoindrie GNU (GNU LGPL) 'This function is governed by the GNU Lesser General Public License (GNU LGPL) 'V 1.1.1 'Parametres : une chaine de 12 chiffres 'Parameters : a 12 digits length string 'Retour : * une chaine qui, affichee avec la police EAN13.TTF, donne le code barre ' * une chaine vide si parametre fourni incorrect 'Return : * a string which give the bar code when it is dispayed with EAN13.TTF font ' * an empty string if the supplied parameter is no good Dim i%, checksum%, first%, CodeBarre$, tableA As Boolean ean13$ = "" 'Verifier qu'il y a 12 caracteres 'Check for 12 characters If Len(chaine$) = 12 Then 'Et que ce sont bien des chiffres 'And they are really digits For i% = 1 To 12 If Asc(Mid$(chaine$, i%, 1)) < 48 Or Asc(Mid$(chaine$, i%, 1)) > 57 Then i% = 0 Exit For End If Next If i% = 13 Then 'Calcul de la cle de controle 'Calculation of the checksum For i% = 12 To 1 Step -2 checksum% = checksum% + Val(Mid$(chaine$, i%, 1)) Next checksum% = checksum% * 3 For i% = 11 To 1 Step -2 checksum% = checksum% + Val(Mid$(chaine$, i%, 1)) Next chaine$ = chaine$ & (10 - checksum% Mod 10) Mod 10 'Le premier chiffre est pris tel quel, le deuxieme vient de la table A 'The first digit is taken just as it is, the second one come from table A CodeBarre$ = Left$(chaine$, 1) & Chr$(65 + Val(Mid$(chaine$, 2, 1))) first% = Val(Left$(chaine$, 1)) For i% = 3 To 7 tableA = False Select Case i% Case 3 Select Case first% Case 0 To 3 tableA = True End Select Case 4 Select Case first% Case 0, 4, 7, 8 tableA = True End Select Case 5 Select Case first% Case 0, 1, 4, 5, 9 tableA = True End Select Case 6 Select Case first% Case 0, 2, 5, 6, 7 tableA = True End Select Case 7 Select Case first% Case 0, 3, 6, 8, 9 tableA = True End Select End Select If tableA Then CodeBarre$ = CodeBarre$ & Chr$(65 + Val(Mid$(chaine$, i%, 1))) Else CodeBarre$ = CodeBarre$ & Chr$(75 + Val(Mid$(chaine$, i%, 1))) End If Next CodeBarre$ = CodeBarre$ & "*" 'Ajout separateur central / Add middle separator For i% = 8 To 13 CodeBarre$ = CodeBarre$ & Chr$(97 + Val(Mid$(chaine$, i%, 1))) Next CodeBarre$ = CodeBarre$ & "+" 'Ajout de la marque de fin / Add end mark ean13$ = CodeBarre$ End If End If End Function
ซึ่งในตัวโปรแกรมจะให้เราใส่ข้อมูลแค่ 12 หลัก ส่วนหลักที่ 13 โปรแกรมจะคำนวณให้ (ตัวที่ 13 เป็น Checksum) ถ้าอยากคีย์เองก็แก้ไข If Len(chaine$) = 13 Then, EANLEN%=13, MaxLength = 13
download โปรแกรม ===> Setup codeEAN13
download Source code ===> ean13.zip
อ้างอิง : http://grandzebu.net/informatique/codbar-en/ean13.htm
0 ความคิดเห็น:
แสดงความคิดเห็น