以下是引用缘吇弹在2007-10-20 0:56:47的发言:
On Error GoTo st
If Len(Text1) = 8 And Mid(Text1, 5, 1) <> "-" And Mid(Text1, 8, 1) <> "-" Then
Text1 = Left(Text1, 4) + "-" + Mid(Text1, 5, 2) + "-" + Right(Text1, 2)
Text2.Text = Format(CDate(Format(Now, "YYYY-MM-DD")) - CDate(Text1.Text), "YYYY") - 1900
ElseIf Not (Len(Text1) = 10 And Mid(Text1, 5, 1) = "-" And Mid(Text1, 8, 1) = "-") Then
st: MsgBox ("职工出生日期输入有误,请检查更正!")
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
Else
Text1 = Format(CDate(Text1.Text))
Text2.Text = Format(CDate(Format(Now, "YYYY-MM-DD")) - CDate(Text1.Text), "YYYY") - 1900
End If
三楼版主太厉害了,一时看不明白,回去慢慢研究.
这段代码是在
private sub text1_change()
end sub
过程中吗?
另:CDate()函数没见过,不知什么意思?