集装箱号(Container Number),也称为集装箱编码,是用于标识集装箱的唯一标识符。集装箱是一种用于装载货物并方便运输的大型金属箱子,常用于海陆空运输。集装箱号是一种用于跟踪和识别集装箱的编号系统,以确保货物在运输过程中的安全性和可追踪性。
方法一:
Function jzxh ( xh )
xh = Application . WorksheetFunction . Trim ( xh )
Dim a ( 1 To 2 , 1 To 36 ) As Integer
Dim i As Integer , j As Integer , n As Long
If Len ( xh ) <> 11 Then
jzxh = "集装箱号无效"
Exit Function
End If
xh = LCase ( xh )
n = 9
For i = 0 To 35
If i < 10 Then
a ( 1 , i + 1 ) = i + 48
a ( 2 , i + 1 ) = i
Else
n = n + 1
a ( 1 , i + 1 ) = 87 + i
If n Mod 11 = 0 Then n = n + 1
a ( 2 , i + 1 ) = n
End If
Next
n = 0
For i = 1 To 10
For j = 1 To 36
If Asc ( Mid ( xh , i , 1 )) = a ( 1 , j ) Then
n = n + a ( 2 , j ) * 2 ^ ( i - 1 )
Exit For
End If
Next
If j = 37 Then
jzxh = "集装箱号无效"
Exit Function
End If
Next
If n Mod 11 = Val ( Right ( xh , 1 )) Then
jzxh = "效验正确"
Else
jzxh = "箱号错误"
End If
End Function
方法二:
Public Function VerifyContainerCode ( ByVal strCode As String ) As Boolean
Const Charcode As String = "0123456789A?BCDEFGHIJK?LMNOPQRSTU?VWXYZ"
Dim i As Long , n As Long , sum As Long
If Len ( strCode ) <> 11 Then Exit Function
For i = 1 To 10
n = InStr ( 1 , Charcode , UCase ( Mid ( strCode , i , 1 ))) - 1
If n = - 1 Or Mid ( strCode , i , 1 ) = "?" Then Exit Function
n = n * 2 ^ ( i - 1 )
sum = sum + n
Next i
sum = ( sum Mod 11 ) Mod 10
If Val ( Mid ( strCode , 11 , 1 )) = sum Then VerifyContainerCode = True
End Function
Public Function ZCode ( ByVal strCode As String ) As String
Const Charcode As String = "0123456789A?BCDEFGHIJK?LMNOPQRSTU?VWXYZ"
Dim i As Long , n As Long , sum As Long
strCode = Application . WorksheetFunction . Trim ( strCode )
If Len ( strCode ) <> 11 Then Exit Function
For i = 1 To 10
n = InStr ( 1 , Charcode , UCase ( Mid ( strCode , i , 1 ))) - 1
If n = - 1 Or Mid ( strCode , i , 1 ) = "?" Then Exit Function
n = n * 2 ^ ( i - 1 )
sum = sum + n
Next i
sum = ( sum Mod 11 ) Mod 10
If Val ( Mid ( strCode , 11 , 1 )) = sum Then
ZCode = "效验正确"
Else
ZCode = "箱号错误"
End If
End Function