如何实现从身份证得知出生年月的问题!?

sksk 2003-10-10 09:10:13
我想只输入身份证号码就可以在下面显示出生年、月、日?
出生年的名称是txtyear,出生月是txtmonth,出生日是txtday.
身分证是txtpersonalid.
我想先能计算出身份证的位数,如果是15位,则txtyear就是“19”+身份证的第六个第七个数字
帮帮我吧!!!
...全文
36 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sksk 2003-10-10
  • 打赏
  • 举报
回复
谢谢,我给分了!
of123 2003-10-10
  • 打赏
  • 举报
回复
dim n as integer
dim strDate as string

n = 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

txlicenhe 2003-10-10
  • 打赏
  • 举报
回复
if len(txtpersonalid) = 15 then
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
射天狼 2003-10-10
  • 打赏
  • 举报
回复
本示例使用 Mid 语句来得到某个字符串中的几个字符。

Dim MyString, FirstWord, LastWord, MidWords
MyString = "Mid Function Demo" 建立一个字符串。
FirstWord = Mid(MyString, 1, 3) ' 返回 "Mid"。
LastWord = Mid(MyString, 14, 4) ' 返回 "Demo"。
MidWords = Mid(MyString, 5) ' 返回 "Funcion Demo"。
射天狼 2003-10-10
  • 打赏
  • 举报
回复
Mid 函数

返回 Variant (String),其中包含字符串中指定数量的字符。

语法

Mid(string, start[, length])

Mid 函数的语法具有下面的命名参数:

部分 说明
string 必要参数。字符串表达式,从中返回字符。如果 string 包含 Null,将返回 Null。
start 必要参数。为 Long。string 中被取出部分的字符位置。如果 start 超过 string 的字符数,Mid 返回零长度字符串 ("")。
length 可选参数;为 Variant (Long)。要返回的字符数。如果省略或 length 超过文本的字符数(包括 start 处的字符),将返回字符串中从 start 到尾端的所有字符。
说明

欲知 string 的字符数,可用 Len 函数。

注意 MidB 函数作用于字符串中包含的字节数据。因此其参数指定的是字节数,而不是字符数。

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧