问题描述
我正在尝试验证vba访问中的EAN 14 UPC代码。我试图在网上找到它,但是没有运气。我刚刚找到了EAN 8和EAN13。因此,我尝试将其编码为类似于EAN 13,如下所示:
I am trying to validate EAN 14 UPC code in vba access. I am trying to find it online but no luck. I just found for EAN 8 and EAN 13. So, I just tried to code it similar to EAN 13 as following:
If Len(Barcode) = 14 Then
'do the check digit for EAN 14 for anything 14 long
checkDigitSubtotal = (Val(Mid(Barcode, 2, 1))) _
+ (Val(Mid(Barcode, 4, 1))) _
+ (Val(Mid(Barcode, 6, 1))) _
+ (Val(Mid(Barcode, 8, 1))) _
+ (Val(Mid(Barcode, 10, 1))) _
+ (Val(Mid(Barcode, 12, 1)))
checkDigitSubtotal = (3 * checkDigitSubtotal) _
+ (Val(Mid(Barcode, 1, 1))) _
+ (Val(Mid(Barcode, 3, 1))) _
+ (Val(Mid(Barcode, 5, 1))) _
+ (Val(Mid(Barcode, 7, 1))) _
+ (Val(Mid(Barcode, 9, 1))) _
+ (Val(Mid(Barcode, 11, 1))) _
+ (Val(Mid(Barcode, 13, 1)))
If Right(Str(300 - checkDigitSubtotal), 1) <> Right(Barcode, 1) Then
Validate_UPC = "EAN14-BAD"
Exit Function
End If
Validate_UPC = "EAN14-GOOD"
Exit Function
End If
它不起作用。我遇到的问题是尽管我输入了有效的EAN,但是却得到了EAN14-BAD。我认为我的验证码无法正常工作。我刚刚在EAN13验证代码上添加了最后一行
+(Val(Mid(Barcode,13,1)))
。
It is not working. Issue I am having is although i enter valid EAN, it gives me EAN14-BAD. I think my validating code is not working. I just added last line+ (Val(Mid(Barcode, 13, 1)))
on EAN13 validation code. Please help.
推荐答案
当我将奇数乘以3时,它的工作原理如下:
It worked when I switched multiplying odd ones by 3 as following:
If Len(Barcode) = 14 Then
checkDigitSubtotal = (Val(Mid(Barcode, 1, 1))) _
+ (Val(Mid(Barcode, 3, 1))) _
+ (Val(Mid(Barcode, 5, 1))) _
+ (Val(Mid(Barcode, 7, 1))) _
+ (Val(Mid(Barcode, 9, 1))) _
+ (Val(Mid(Barcode, 11, 1))) _
+ (Val(Mid(Barcode, 13, 1)))
checkDigitSubtotal = (3 * checkDigitSubtotal) _
+ (Val(Mid(Barcode, 2, 1))) _
+ (Val(Mid(Barcode, 4, 1))) _
+ (Val(Mid(Barcode, 6, 1))) _
+ (Val(Mid(Barcode, 8, 1))) _
+ (Val(Mid(Barcode, 10, 1))) _
+ (Val(Mid(Barcode, 12, 1)))
If Right(Str(300 - checkDigitSubtotal), 1) <> Right(Barcode, 1) Then
Validate_UPC = "EAN14-BAD"
Exit Function
End If
Validate_UPC = "EAN14-GOOD"
Exit Function
End If
这篇关于如何计算EAN-14的校验和数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!