Dear Friends,
I am trying to create EAN13 Barcodes (for ISBN Numbers) and have had little joy with other methods using that wrapped barcode class in java but I have made some progress with this method (in Excel anyway) which utilises a special EAN13 font and a sub to create a character chain which the font turns into a working barcode.
Sadly, Maths is not my strong point, and after reading this, you might conclude that programming isn't either... and I'm having difficulty translating this Sub into B4x, particularly the maths.
The code was originally written in French, which didn't help my undertsanding. The IDE particularly objects to the Mod functions and subtituting string.CharAt(0) to get the leftmost character makes it very upset. I translated I%, checksum%, first% as Ints and CodeBarre$, Chaine$ as Strings...
Any insights/hints would be appreciated.
I am trying to create EAN13 Barcodes (for ISBN Numbers) and have had little joy with other methods using that wrapped barcode class in java but I have made some progress with this method (in Excel anyway) which utilises a special EAN13 font and a sub to create a character chain which the font turns into a working barcode.
Sadly, Maths is not my strong point, and after reading this, you might conclude that programming isn't either... and I'm having difficulty translating this Sub into B4x, particularly the maths.
The code was originally written in French, which didn't help my undertsanding. The IDE particularly objects to the Mod functions and subtituting string.CharAt(0) to get the leftmost character makes it very upset. I translated I%, checksum%, first% as Ints and CodeBarre$, Chaine$ as Strings...
Any insights/hints would be appreciated.
B4X:
Public Function ean13$(chaine$)
'************************MACRO FONCTION EAN13***************************************************
'************************--------------------***************************************************
'Parameters: a 12-digit string
'Return: * a chain which, displayed with the EAN13.TTF font, gives the barcode
'* an empty string if parameter supplied incorrect
'Originally in French, comments updated by Google Translate...
'
Dim I%, checksum%, first%, CodeBarre$, tableA As Boolean
ean13$ = ""
'Check it is 12 chars
If Len(chaine$) = 12 Then
'then work through it
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 clé de contrôle
For I% = 2 To 12 Step 2
checksum% = checksum% + Val(Mid$(chaine$, I%, 1))
Next
checksum% = checksum% * 3
For I% = 1 To 11 Step 2
checksum% = checksum% + Val(Mid$(chaine$, I%, 1))
Next
chaine$ = chaine$ & (10 - checksum% Mod 10) Mod 10
''The first number is taken as is, the second comes 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$ & "*" 'add separator character of font
For I% = 8 To 13
CodeBarre$ = CodeBarre$ & Chr$(97 + Val(Mid$(chaine$, I%, 1)))
Next
CodeBarre$ = CodeBarre$ & "+" 'add final char of font
ean13$ = CodeBarre$
End If
End If
End Function