随机生成身份证号码
'随机生成身份证号码‘sex 返回性别01(男)00(女),indentitycode返回省份证号码
Function User_CreateIdentifyCard(byref Sex as string,byref IdentityCode as string)
Dim AreaCode,Birthday,SequenceCode,CheckoutCode as string
Dim upper,lower,randomvalue as integer
Dim i,s,y,a(),w() as integer
'产生随机的地址码,前两位固定为00,后四位随机
AreaCode="00"
lower=0
upper=9999
Randomize time()
randomvalue=int((upper-lower+1)*Rnd+lower)
AreaCode=AreaCode & cstr(Format(randomvalue,"0000"))
redim a(1 to 17)
redim w(1 to 17)
'随机产生出生日期的年月日
lower=1960
upper=1985
Randomize time()
randomvalue=int((upper-lower+1)*Rnd+lower)
Birthday=cstr(randomvalue)
lower=1
upper=12
Randomize time()
randomvalue=int((upper-lower+1)*Rnd+lower)
Birthday=Birthday & cstr(Format(randomvalue,"00"))
lower=1
upper=28
Randomize time()
randomvalue=int((upper-lower+1)*Rnd+lower)
Birthday=Birthday & cstr(Format(randomvalue,"00"))
'随机产生3位顺序码,奇数的是男性,偶数的是女性
lower=000
upper=999
Randomize time()
randomvalue=int((upper-lower+1)*Rnd+lower)
SequenceCode=cstr(Format(randomvalue,"000"))
if (SequenceCode mod 2)=0 then
Sex="00"
else
Sex="01"
end if
'计算最后一位校验码 ,至于计算公式,可以google下
a(1)=cint(mid(AreaCode,1,1))
a(2)=cint(mid(AreaCode,2,1))
a(3)=cint(mid(AreaCode,3,1))
a(4)=cint(mid(AreaCode,4,1))
a(5)=cint(mid(AreaCode,5,1))
a(6)=cint(mid(AreaCode,6,1))
a(7)=cint(mid(Birthday,1,1))
a(8)=cint(mid(Birthday,2,1))
a(9)=cint(mid(Birthday,3,1))
a(10)=cint(mid(Birthday,4,1))
a(11)=cint(mid(Birthday,5,1))
a(12)=cint(mid(Birthday,6,1))
a(13)=cint(mid(Birthday,7,1))
a(14)=cint(mid(Birthday,8,1))
a(15)=cint(mid(SequenceCode,1,1))
a(16)=cint(mid(SequenceCode,2,1))
a(17)=cint(mid(SequenceCode,3,1))
w(1)=7
w(2)=9
w(3)=10
w(4)=5
w(5)=8
w(6)=4
w(7)=2
w(8)=1
w(9)=6
w(10)=3
w(11)=7
w(12)=9
w(13)=10
w(14)=5
w(15)=8
w(16)=4
w(17)=2
s=0
for i=1 to 17
s=s+a(i)*w(i)
next i
y=s mod 11
select case y
case 0
CheckoutCode="1"
case 1
CheckoutCode="0"
case 2
CheckoutCode="X"
case 3
CheckoutCode="9"
case 4
CheckoutCode="8"
case 5
CheckoutCode="7"
case 6
CheckoutCode="6"
case 7
CheckoutCode="5"
case 8
CheckoutCode="4"
case 9
CheckoutCode="3"
case 10
CheckoutCode="2"
end select
IdentityCode=AreaCode & Birthday & SequenceCode & CheckoutCode
End Function
[ 本帖最后由 yangjingxiao 于 2006-4-21 22:13 编辑 ] 如果旁边有解释就好 加了一点点注释,语法上的,可以看帮助
页:
[1]