modold.bas

来自「一个用VB开发的非常不错的企业ERP管理源码,值得一看.」· BAS 代码 · 共 33 行

BAS
33
字号
Attribute VB_Name = "ModOld"
'计年龄
Public Old  '年龄

Public Function ExactAge(BirthDate As Variant) As String
Dim yer As Integer, mon As Integer, d As Integer
Dim dt As Date
Dim sAns  As String
    If Not IsDate(BirthDate) Then Exit Function
    dt = CDate(BirthDate)
    If dt > Now Then Exit Function
    
    yer = Year(dt)
    mon = Month(dt)
    d = Day(dt)
    yer = Year(Date) - yer
    mon = Month(Date) - mon
    d = Day(Date) - d
    If Sgn(d) = -1 Then
        d = 30 - Abs(d)
        mon = mon - 1
    End If
    If Sgn(mon) = -1 Then
        mon = 12 - Abs(mon)
        yer = yer - 1
    End If
    
sAns = yer & " year(s) " & mon & " month(s) " & d _
  & " day(s) old."
ExactAge = sAns
Old = yer
End Function

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?