集装柜 柜号验证

标准柜号构成基本概念:采用ISO6346(1995)标准。

标准集装箱箱号由11位编码组成,包括三个部分:(4位英文字母+6位数字+1位校验码)

1、 第一部分由4位英文字母组成。前三位代码 (Owner Code) 主要说明箱主、经营人,第四位代码说明集装箱的类型(所有海运柜子的第四个字母,都是U,是用于海运集装箱的代号)。列如CBHU 开头的标准集装箱是表明箱主和经营人为中远集运。

2、 第二部分由6位数字组成。是箱体注册码(Registration Code),用于一个集装箱箱体持有的唯一标识。

3、 第三部分为校验码(Check Digit)由前4位字母和6位数字经过校验规则运算得到,用于识别在校验时是否发生错误。即第11位数字。

根据校验规则箱号的每个字母和数字都有一个运算的对应值。箱号的前10位字母和数字的对应值从0到Z对应数值为0到38,11、22、33不能对11取模数,所以要除去

第N位的箱号对应值再分别乘以2的N-1次方 (N=1,2,3………..10)

例如:箱号为CBHU3202732的集装箱它的第1位代码为C,

它的代码值=代码的对应值×2的0次方 =13×1=13。

类推第2位代码为B

它的代码值=代码的对应值×2的1次方 =12×2=24

以此类推得到箱号前10位代码的代码值。

将前10位的代码值乘积累加后对11取模

箱号为CBHU3202732的集装箱前10位箱号的代码累加值=4061,取11的模后为2,就是这个箱号第11位的识别码的数值。

公式

校验码S=∑Ci*2

以此类推,就能得到校验码。

 

 

Public Sub 集装箱编码验证()
  On Error Resume Next
  Dim row1 As Integer, col1 As Integer, b As Integer
  Dim row2 As Integer, col2 As Integer, c As Integer
  row1 = Range(Selection.Address).Row
  row2 = Range(Selection.Address).Rows.Count + row1 - 1
  col1 = Range(Selection.Address).Column
  col2 = Range(Selection.Address).Columns.Count + col1 - 1
  d = 0
  For i = row1 To row2
  For j = col1 To col2
  c = 0
  For k = 1 To 10 '取字符计算循环
  If Len(Cells(i, j)) = 11 Then
  a = Mid(LCase(Cells(i, j)), k, 1)
  Select Case a
  Case Is = "0"
  b = 0
  Case Is = "1"
  b = 1
  Case Is = "2"
  b = 2
  Case Is = "3"
  b = 3
  Case Is = "4"
  b = 4
  Case Is = "5"
  b = 5
  Case Is = "6"
  b = 6
  Case Is = "7"
  b = 7
  Case Is = "8"
  b = 8
  Case Is = "9"
  b = 9
  Case Is = "a"
  b = 10
  Case Is = "b"
  b = 12
  Case Is = "c"
  b = 13
  Case Is = "d"
  b = 14
  Case Is = "e"
  b = 15
  Case Is = "f"
  b = 16
  Case Is = "g"
  b = 17
  Case Is = "h"
  b = 18
  Case Is = "i"
  b = 19
  Case Is = "j"
  b = 20
  Case Is = "k"
  b = 21
  Case Is = "l"
  b = 23
  Case Is = "m"
  b = 24
  Case Is = "n"
  b = 25
  Case Is = "o"
  b = 26
  Case Is = "p"
  b = 27
  Case Is = "q"
  b = 28
  Case Is = "r"
  b = 29
  Case Is = "s"
  b = 30
  Case Is = "t"
  b = 31
  Case Is = "u"
  b = 32
  Case Is = "v"
  b = 34
  Case Is = "w"
  b = 35
  Case Is = "x"
  b = 36
  Case Is = "y"
  b = 37
  Case Is = "z"
  b = 38
  Case Else
  Cells(i, j).Interior.ColorIndex = 3

  d = d + 1
  Exit For
    
  End Select
    
  c = 2 ^ (k - 1) * b + c
  Else
  End If
  Next k
  If (c Mod 11) Mod 10 <> Mid(Cells(i, j), 11, 1) Then
  Cells(i, j).Interior.ColorIndex = 3 '不符合填充红色
    
  d = d + 1
  Else
  Cells(i, j).Interior.ColorIndex = 4
  End If
    
  Next j
  Next i
   
  MsgBox "有" & d & "处箱号错误或为空。绿色填充为正确箱号。"
  Workbooks("集装箱编码校验.xls").Close
End Sub

  

你可能感兴趣的:(集装柜 柜号验证)