以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  车辆VIN码校验位算法  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=76029)

--  作者:wjl-se
--  发布时间:2015/10/20 11:44:00
--  车辆VIN码校验位算法

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:车辆识别码vin校验位计算方法.rar

 

算法在附件中,百度得来,问题是水平太低,求老师帮忙写个代码,谢谢。


--  作者:大红袍
--  发布时间:2015/10/20 11:47:00
--  
直接去拿例子的代码配上去。
--  作者:wjl-se
--  发布时间:2015/10/20 11:56:00
--  

我能想到的办法是建数据表去查询,再计算,可能比较笨,有没有可能全写在代码里?


--  作者:大红袍
--  发布时间:2015/10/20 12:18:00
--  

mark 车辆识别码

 

Dim q() As Integer = {8,7,6,5,4,3,2,10,1,9,8,7,6,5,4,3,2}
Dim v() As Integer = {0,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,1,2,3,4,5,7,9,2,3,4,5,6,7,8,9}
Dim w() As String = {0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F","G","H","J","K","L","M","N","P","R","S","T","U","V","W","X","W","Z"}
Dim num As String = "UU6JA69691D713820"
Dim sum As Double = 0
For i As Integer = 0 To num.length - 1
    Dim s As String = num(i)
    sum += v(array.indexOf(w,s.ToUpper)) * q(i)
Next
Dim n9 As String = num(8)
sum = (sum - n9) Mod 11
msgbox(sum)

[此贴子已经被作者于2015/10/20 12:18:32编辑过]

--  作者:wjl-se
--  发布时间:2015/10/20 12:52:00
--  
谢谢,非常感谢!
--  作者:wjl-se
--  发布时间:2015/10/20 13:30:00
--  

红袍老师,还有一种特殊情况:

如果余数为10,校验码为字母X

比如:LFP83ACCXD1D99699,4楼的算法不灵了


--  作者:wjl-se
--  发布时间:2015/10/20 13:51:00
--  

代码看了个大概,改了改就行了:

Dim q() As Integer = {8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2}
Dim v() As Integer = {0,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,1,2,3,4,5,7,9,2,3,4,5,6,7,8,9}
Dim w() As String = {0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F","G","H","J","K","L","M","N","P","R","S","T","U","V","W","X","Y","Z"}
Dim num As String = "LFP83ACCXD1D99699"
Dim sum As Double = 0
For i As Integer = 0 To num.length - 1
    Dim s As String = num(i)
    sum += v(array.indexOf(w,s.ToUpper)) * q(i)
Next
Dim n9 As String = IIF(sum Mod 11 = 10, "X", sum Mod 11)
msgbox(n9)

[此贴子已经被作者于2015/10/20 15:03:09编辑过]