
- 129 -
When CD
type is A(EAN (JAN) or UPC):
This function identifies the code type (EAN or UPC) based upon the data length (number of
digits) as shown below.
If the data length is other than 13, 8, or 7, this function returns "0" and throws an exception.
No. of Digits in Barcode Data Barcode type
13 EAN-13 (JAN-13), UPC-A
8 EAN-8 (JAN-8)
7 UPC-E
To check whether the CD type is correct, pass a piece of barcode data with a CD to the
Scanner.GetChkDigit method as shown below. If the returned value is equal to the CD,
then the CD is correct.
[VB]
If (Scanner.GetChkDigit("49400458", "A") = Asc("8")) Then
Console.WriteLine ("CD OK")
End If
[C#]
UnicodeEncoding encode = new UnicodeEncoding();
if (Scanner.GetChkDigit("49400458", 'A') == (int)encode.GetBytes("8")[0]) {
Console.WriteLine ("CD OK");
}
To append a CD to the barcode data, pass a piece of barcode data with a dummy character
appended to the Scanner.GetChkDigit method as shown below. The returned value will be
the CD. Replace the dummy character with the returned value.
[VB]
Dim origData As String = "4940045"
Dim digit As Integer = Scanner.GetChkDigit(origData+"0", "A")
Console.WriteLine("CD = {0}", origData + New String(Chr(digit), 1))
[C#]
string origData = "4940045";
int digit = Scanner.GetChkDigit(origData+"0", 'A');
byte[] digitByteArray = {(byte)digit};
ASCIIEncoding encode = new ASCIIEncoding();
Console.WriteLine("CD = {0}", origData + encode.GetString(digitByteArray, 0, 1));
Result
> CD = 49400458
Kommentare zu diesen Handbüchern