Private Sub Command1_Click()
Text2.Text = Left(Text1.Text, 1) & "/" & Mid(Text1.Text, 2, 1) & "/" & Right(Text1.Text, 1)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
Text2.Text = Left(Text1.Text, 1) & "/" & Mid(Text1.Text, 2, 1) & "/" & Right(Text1.Text, 1)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
当然用MAskedtbox控件也行,设置它的mask属性
那输入2222是表示22/2/2还是表示2/2/22 ?
用mask控件较好,用text控件,你就得在keypress中控制。
Dim xx, yy As String
If Text1 <> "" Then
xx = Trim(Text1.Text)
Text1 = Mid(xx, 1, 4) & "/" & Mid(xx, 5, 2) & "/" & Mid(xx, 7, 2)
If Not IsDate(Text1) Then
Cancel = True
MsgBox "请按 yyyymmdd 格式输入", , "系统信息提示"
Text1 = ""
End If
End If