nbsp;
If Len(Text1.Text) = 4 Then
Text1.Text = Text1.Text + "-"
Text1.SelStart = Len(Text1.Text)
End If ''当年份正确输入后就自动加上的“-”分隔符
''---------------------------------------------------------------------------
''月份输入的控制
''---------------------------------------------------------------------------
If Len(Text1.Text) = 6 Then
If Right((Text1.Text), 1) <> "0" And Right((Text1.Text), 1) <> "1" Then
If Right((Text1.Text), 1) = "2" Or Right((Text1.Text), 1) = "3" Or _
Right((Text1.Text), 1) = "4" Or Right((Text1.Text), 1) = "5" Or _
Right((Text1.Text), 1) = "6" Or Right((Text1.Text), 1) = "7" Or _
Right((Text1.Text), 1) = "8" Or Right((Text1.Text), 1) = "9" Then
a = Right((Text1.Text), 1)
Text1.Text = Left((Text1.Text), 5) + "0" + a + "-"
''如果这样,那下面一段if len(text1.text)=7的判断自然就自动跳过去了。
Text1.SelStart = Len(Text1.Text)
Else ''限制只能输入“0-9”
Text1.Text = Left((Text1.Text), Len(Text1.Text) - 1)
Text1.SelStart = Len(Text1.Text)
End If
End If
End If
If Len(Text1.Text) = 7 Then
If Left(Right(Text1.Text, 2), 1) = "0" Then ''如果月份第一位为“0”
If Right((Text1.Text), 1) <> "1" And Right((Text1.Text), 1) <> "2" And _
Right((Text1.Text), 1) <> "3" And Right((Text1.Text), 1) <> "4" And _
Right((Text1.Text), 1) <> "5" And Right((Text1.Text), 1) <> "6" And _
Right((Text1.Text), 1) <> "7" And Right((Text1.Text), 1) <> "8" And _
Right((Text1.Text), 1) <> "9" Then
Text1.Text = Left((Text1.Text), Len(Text1.Text) - 1)
Text1.SelStart = Len(Text1.Text)
Else
Text1.Text = Text1.Text + "-" ''当月份输入正确后自动加一个“-”分隔符
Text1.SelStart = Len(Text1.Text)
Exit Sub ''少不了!如果少,那当月份为“01”时,紧接的IfEnd IF就
''成立,这样会在这里出现死循环,而出现溢出堆栈空间的错误!
''注:本程序好几个地方都可以用上Exit Sub,要加你自己补上吧!
End If
End If
If Left(Right((Text1.Text), 2), 1) = "1" Then ''如果月份第一位为“1”
If Right((Text1.Text), 1) <> "0" And Right((Text1.Text), 1) <> "1" And _
Right((Text1.Text), 1) <> "2" Then
Text1.Text = Left((Text1.Text), Len(Text1.Text) - 1)
Text1.SelStart = Len(Text1.Text)
Else
Text1.Text = Text1.Text + "-" ''当月份输入正确后自动加一个“-”分隔符
Text1.Sel