VB编程题,怎么做啊???麻烦详细代码,谢谢啦
1、编写一个身份证号码转换程序:(1)老身份证是15位,先要增加两位年份,变成17位,再计算校验位。(2)校验位的计算方法是:17位身份证号码Number每一位都乘上一个...
1、 编写一个身份证号码转换程序:
(1) 老身份证是15位,先要增加两位年份,变成17位,再计算校验位。
(2) 校验位的计算方法是:17位身份证号码Number每一位都乘上一个权值Weight,然后相加,再除以11,取其余数作为位置数Position。
(3) 根据位置数Position查表,得到校验位CheckCode。
(4) Number[i]: 表示身份证号码第 i 位上的号码
Weight[i]: 表示第 i 位上的权值
Weight :7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 1
Position = ∑(Number[i]*Weight[i]) mod 11
(5) Position :0 1 2 3 4 5 6 7 8 9 10
CheckCode:1 0 X 9 8 7 6 5 4 3 2
其中罗马数字X表示10,所以在新标准的身份证号码中可能含有非数字的字母X。 展开
(1) 老身份证是15位,先要增加两位年份,变成17位,再计算校验位。
(2) 校验位的计算方法是:17位身份证号码Number每一位都乘上一个权值Weight,然后相加,再除以11,取其余数作为位置数Position。
(3) 根据位置数Position查表,得到校验位CheckCode。
(4) Number[i]: 表示身份证号码第 i 位上的号码
Weight[i]: 表示第 i 位上的权值
Weight :7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 1
Position = ∑(Number[i]*Weight[i]) mod 11
(5) Position :0 1 2 3 4 5 6 7 8 9 10
CheckCode:1 0 X 9 8 7 6 5 4 3 2
其中罗马数字X表示10,所以在新标准的身份证号码中可能含有非数字的字母X。 展开
1个回答
展开全部
新建工程,添加两个文本框Text1和Text2,添加一个按钮Command1.
代码如下。
以下假设要转换的都是19XX年出生的。
Dim Weight(17) As Integer
Dim CheckCode As String
Private Sub Command1_Click()
Dim i As Integer
Dim OldID As String, NewID As String
Dim Position As Integer
OldID = Left(Text1.Text, 6) & "19" & Right(Text1.Text, 9)
For i = 1 To 17
Position = Position + Val(Mid(OldID, i, 1)) * Weight(i)
Next i
Position = Position Mod 11
NewID = OldID & Mid(CheckCode, Position + 1, 1)
Text2.Text = NewID
End Sub
Private Sub Form_Load()
Weight(1) = 7
Weight(2) = 9
Weight(3) = 10
Weight(4) = 5
Weight(5) = 8
Weight(6) = 4
Weight(7) = 2
Weight(8) = 1
Weight(9) = 6
Weight(10) = 3
Weight(11) = 7
Weight(12) = 9
Weight(13) = 10
Weight(14) = 5
Weight(15) = 8
Weight(16) = 4
Weight(17) = 2
CheckCode = "10X98765432"
End Sub
代码如下。
以下假设要转换的都是19XX年出生的。
Dim Weight(17) As Integer
Dim CheckCode As String
Private Sub Command1_Click()
Dim i As Integer
Dim OldID As String, NewID As String
Dim Position As Integer
OldID = Left(Text1.Text, 6) & "19" & Right(Text1.Text, 9)
For i = 1 To 17
Position = Position + Val(Mid(OldID, i, 1)) * Weight(i)
Next i
Position = Position Mod 11
NewID = OldID & Mid(CheckCode, Position + 1, 1)
Text2.Text = NewID
End Sub
Private Sub Form_Load()
Weight(1) = 7
Weight(2) = 9
Weight(3) = 10
Weight(4) = 5
Weight(5) = 8
Weight(6) = 4
Weight(7) = 2
Weight(8) = 1
Weight(9) = 6
Weight(10) = 3
Weight(11) = 7
Weight(12) = 9
Weight(13) = 10
Weight(14) = 5
Weight(15) = 8
Weight(16) = 4
Weight(17) = 2
CheckCode = "10X98765432"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询