字符型,使用方便。
AfterEdit
Dim y As String = Left((e.Row("日期")),2)
Dim d As String = Right((e.Row("日期")),2)
Dim ys1() As String = {"01","03","05","07","08","10","12"}
Dim ys2() As String = {"04","06","09","11"}
If e.Col.Name = "日期" Then
If e.Row("日期").Length = 4 Then
For i As Integer = 0 To ys1.Length - 1
For j As Integer = 0 To ys2.Length - 1
If val(y) > 12 OrElse (y.StartsWith(ys1(i)) AndAlso val(d) > 31) OrElse (y.StartsWith(ys2(j)) AndAlso val(d) > 30) OrElse (y.StartsWith("02") AndAlso val(d) > 28) Then
e.Row("日期") = ""
MessageBox.Show("年月日有误")
e.Table.Select(e.Row.Index,e.Col.Index - 1)
Return
Else
e.Row("日期") = Right((Date.Today().Year),2) & "-" & y & "-" & d
End If
Next
Next
End If
End If