text1.text怎么限定输入的是日期格式啊,麻烦你了,谢谢哈
3个回答
展开全部
比较简单的方法是选用MonthView控件,在"工程"->"部件"中勾选"Microsoft Windows Common Controls-2.6.0"该控件便出现在工具栏中。在窗体上画出MonthView后用以下代码:
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
Text1.Text = MonthView1.Value
End Sub
也可以通过代码使Text1中只能输入日期格式,例如:
Dim txtcg As Integer '此变量需在窗体模块的顶部声明段声明
Private Sub Text1_Change()
i = Text1.SelStart
If txtcg = 1 Then Exit Sub
txtcg = 1
t1 = Left(Text1, i) & Replace(Replace(Mid(Text1, i + 1), "-", ""), "_", "")
If 10 - Len(t1) > 0 Then t1 = t1 & String(10 - Len(t1), "_")
If Mid(t1, 5, 1) <> "-" Then t1 = Left(t1, 4) & "-" & Mid(t1, 5)
If Mid(t1, 8, 1) <> "-" Then t1 = Left(t1, 7) & "-" & Mid(t1, 8)
Text1 = Left(t1, 10)
Text1.SelStart = i
txtcg = 0
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If IsNumeric(Chr(KeyAscii)) Then
If Text1.SelStart >= 10 Then KeyAscii = 0: Exit Sub
If Text1.SelStart = 4 Or Text1.SelStart = 7 Then
Text1.SelStart = Text1.SelStart + 1
End If
ElseIf KeyAscii = 8 Then
If Text1.SelStart = 0 Then KeyAscii = 0
Else
KeyAscii = 0
End If
End Sub
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
Text1.Text = MonthView1.Value
End Sub
也可以通过代码使Text1中只能输入日期格式,例如:
Dim txtcg As Integer '此变量需在窗体模块的顶部声明段声明
Private Sub Text1_Change()
i = Text1.SelStart
If txtcg = 1 Then Exit Sub
txtcg = 1
t1 = Left(Text1, i) & Replace(Replace(Mid(Text1, i + 1), "-", ""), "_", "")
If 10 - Len(t1) > 0 Then t1 = t1 & String(10 - Len(t1), "_")
If Mid(t1, 5, 1) <> "-" Then t1 = Left(t1, 4) & "-" & Mid(t1, 5)
If Mid(t1, 8, 1) <> "-" Then t1 = Left(t1, 7) & "-" & Mid(t1, 8)
Text1 = Left(t1, 10)
Text1.SelStart = i
txtcg = 0
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If IsNumeric(Chr(KeyAscii)) Then
If Text1.SelStart >= 10 Then KeyAscii = 0: Exit Sub
If Text1.SelStart = 4 Or Text1.SelStart = 7 Then
Text1.SelStart = Text1.SelStart + 1
End If
ElseIf KeyAscii = 8 Then
If Text1.SelStart = 0 Then KeyAscii = 0
Else
KeyAscii = 0
End If
End Sub
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询