我想只输入身份证号码就可以在下面显示出生年、月、日?
出生年的名称是txtyear,出生月是txtmonth,出生日是txtday.
身分证是txtpersonalid.
我想先能计算出身份证的位数,如果是15位,则txtyear就是“19”+身份证的第六个第七个数字
帮帮我吧!!!
出生年的名称是txtyear,出生月是txtmonth,出生日是txtday.
身分证是txtpersonalid.
我想先能计算出身份证的位数,如果是15位,则txtyear就是“19”+身份证的第六个第七个数字
帮帮我吧!!!
string 必要参数。字符串表达式,从中返回字符。如果 string 包含 Null,将返回 Null。
start 必要参数。为 Long。string 中被取出部分的字符位置。如果 start 超过 string 的字符数,Mid 返回零长度字符串 ("")。
length 可选参数;为 Variant (Long)。要返回的字符数。如果省略或 length 超过文本的字符数(包括 start 处的字符),将返回字符串中从 start 到尾端的所有字符。
说明欲知 string 的字符数,可用 Len 函数。注意 MidB 函数作用于字符串中包含的字节数据。因此其参数指定的是字节数,而不是字符数。
MyString = "Mid Function Demo" 建立一个字符串。
FirstWord = Mid(MyString, 1, 3) ' 返回 "Mid"。
LastWord = Mid(MyString, 14, 4) ' 返回 "Demo"。
MidWords = Mid(MyString, 5) ' 返回 "Funcion Demo"。
txtyear = '19'+mid(txtpersonalid,7,2)
txtmonth = mid(txtpersonalid,9,2)
txtday = mid(txtpersonalid,11,2)
else
txtyear = mid(txtpersonalid,7,4)
txtmonth = mid(txtpersonalid,11,2)
txtday = mid(txtpersonalid,13,2)
end
dim strDate as stringn = len(txtpersonalid)
if n <> 15 and n <> 18 then
msgbox "身份号码位数不正确!"
txtpersonalid.setfocus
exit sub
end if
strDate = left(iif(n = 15, "19", "") & mid(txtpersonalid, 7, 8), 8)
txtyear = left(strDate, 4)
txtmonth = mid(strdate, 3, 2)
txtday = right(strDate, 2)if not isdate(txtyear & "-" & txtmonth & "-" & txtday) then
txtyear = ""
txtmonth = ""
txtday = ""
msgbox "身份号码中日期部分不正确!"
txtpersonalid.setfocus
end if