以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助] 怎么利用函数,从身份证号码中读出 出生年月日、年龄、性别呢?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=130730)

--  作者:龙潭春早
--  发布时间:2019/1/30 15:48:00
--  [求助] 怎么利用函数,从身份证号码中读出 出生年月日、年龄、性别呢?
表中有 身份证号码 和 出生年月日、年龄、性别 几列。

想从身份证号码中,读出 出生年月日、年龄、性别等,要怎么用函数读出呢?

知道有 ReadSex、ReadBirthDay 这些函数,要怎么设置呢?

--  作者:lunengcheng
--  发布时间:2019/1/30 15:58:00
--  
我的代码,可以参考一下,放在表的DataColChanged里面:

\'根据身份证号码生成年龄和性别列
Select Case e.DataCol.Name
    Case "身份证号"
        If e.DataRow.IsNull("身份证号") Then  \'身份证号码是否为空
            e.DataRow("出生日期") = Nothing  \'如果为空,则清除出生日期
            e.DataRow("性别") = Nothing  \'如果为空,则清除出生日期
            e.DataRow("年龄") = Nothing \'如果为空,则清除年龄
        Else
            \'否则从身份证号码列中提取出生日期
            e.DataRow("出生日期") = ReadBirthday(e.DataRow("身份证号"))
            e.DataRow("性别") = ReadSex(e.DataRow("身份证号"))
            Dim d As Date = ReadBirthday(e.DataRow("身份证号"))
            Dim y As Integer = d.year
            If format(d, "MMdd") <= Format(Date.Today, "MMdd") Then
                e.DataRow("年龄") = Date.Today.Year - y
            Else
                e.DataRow("年龄") = Date.Today.Year - y
            End If
        End If
End Select


--  作者:龙潭春早
--  发布时间:2019/1/30 17:08:00
--  
下面的代码,重复了两次,不对吧?

e.DataRow("年龄") = Date.Today.Year - y


--  作者:有点甜
--  发布时间:2019/1/30 22:11:00
--  
datacolchanged事件

 

Select Case e.DataCol.Name
    Case "身份证号"
        If e.DataRow.IsNull("身份证号") Then  \'身份证号码是否为空
            e.DataRow("出生日期") = Nothing  \'如果为空,则清除出生日期
            e.DataRow("性别") = Nothing  \'如果为空,则清除出生日期
            e.DataRow("年龄") = Nothing \'如果为空,则清除年龄
        Else
            \'否则从身份证号码列中提取出生日期
            e.DataRow("出生日期") = ReadBirthday(e.DataRow("身份证号"))
            e.DataRow("性别") = ReadSex(e.DataRow("身份证号"))
            Dim d As Date = ReadBirthday(e.DataRow("身份证号"))
            Dim y As Integer = d.year
            If format(d, "MMdd") <= Format(Date.Today, "MMdd") Then
                e.DataRow("年龄") = Date.Today.Year - y
            Else
                e.DataRow("年龄") = Date.Today.Year - y -1
            End If
        End If
End Select


--  作者:浪花兄弟
--  发布时间:2019/6/30 22:57:00
--  
 提示未声明名称 ReadBirthday、ReadSex、ReadBirthday?
--  作者:有点甜
--  发布时间:2019/7/1 10:46:00
--  
以下是引用浪花兄弟在2019/6/30 22:57:00的发言:
 提示未声明名称 ReadBirthday、ReadSex、ReadBirthday?

 

卸载重新安装最新版foxtable。