'首先保证只能输入数字: Private Sub text1_KeyPress(KeyAscii As Integer) 'text1:年份输入文本框 If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then KeyAscii = 0 End If End SubPrivate Sub text2_KeyPress(KeyAscii As Integer) 'text2:月份输入文本框 If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then KeyAscii = 0 End If End Sub '然后在lostfocus事件中判断: Private Sub Text1_LostFocus()'判断年份 If Val(Text1) < 0 Or Val(Text1) > 9999 Then MsgBox ("输入年份非法!") End If Text1.SetFocus End SubPrivate Sub Text2_LostFocus()'判断月份 If Val(Text2) < 0 Or Val(Text2) > 12 Then MsgBox ("输入月份非法!") End If Text2.SetFocus End Sub
Val(Text2) < 1
'重发一次'首先保证只能输入数字: Private Sub text1_KeyPress(KeyAscii As Integer) 'text1:年份输入文本框 If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then KeyAscii = 0 End If End SubPrivate Sub text2_KeyPress(KeyAscii As Integer) 'text2:月份输入文本框 If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then KeyAscii = 0 End If End Sub '然后在lostfocus事件中判断: Private Sub Text1_LostFocus()'判断年份 If Val(Text1) < 0 Or Val(Text1) > 9999 Then MsgBox ("输入年份非法!") End If Text1.SetFocus End SubPrivate Sub Text2_LostFocus()'判断月份 If Val(Text2) < 1 Or Val(Text2) > 12 Then MsgBox ("输入月份非法!") End If Text2.SetFocus End Sub
MonthView 控件的Year 属性可以设置为从 1601 到 9999 的任意整数。
实在不好意思,没做测试'首先保证只能输入数字: Private Sub text1_KeyPress(KeyAscii As Integer) 'text1:年份输入文本框 If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then KeyAscii = 0 End If End SubPrivate Sub text2_KeyPress(KeyAscii As Integer) 'text2:月份输入文本框 If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then KeyAscii = 0 End If End Sub '然后在lostfocus事件中判断: Private Sub Text1_LostFocus() '判断年份 If Val(Text1) < 1 Or Val(Text1) > 9999 Then MsgBox ("输入年份非法!") Text1.SetFocus End IfEnd SubPrivate Sub Text2_LostFocus() '判断月份 If Val(Text2) < 1 Or Val(Text2) > 12 Then MsgBox ("输入月份非法!") Text2.SetFocus End IfEnd Sub
'首先保证只能输入数字:
Private Sub text1_KeyPress(KeyAscii As Integer) 'text1:年份输入文本框
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End SubPrivate Sub text2_KeyPress(KeyAscii As Integer) 'text2:月份输入文本框
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
'然后在lostfocus事件中判断:
Private Sub Text1_LostFocus()'判断年份
If Val(Text1) < 0 Or Val(Text1) > 9999 Then
MsgBox ("输入年份非法!")
End If
Text1.SetFocus
End SubPrivate Sub Text2_LostFocus()'判断月份
If Val(Text2) < 0 Or Val(Text2) > 12 Then
MsgBox ("输入月份非法!")
End If
Text2.SetFocus
End Sub
'重发一次'首先保证只能输入数字:
Private Sub text1_KeyPress(KeyAscii As Integer) 'text1:年份输入文本框
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End SubPrivate Sub text2_KeyPress(KeyAscii As Integer) 'text2:月份输入文本框
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
'然后在lostfocus事件中判断:
Private Sub Text1_LostFocus()'判断年份
If Val(Text1) < 0 Or Val(Text1) > 9999 Then
MsgBox ("输入年份非法!")
End If
Text1.SetFocus
End SubPrivate Sub Text2_LostFocus()'判断月份
If Val(Text2) < 1 Or Val(Text2) > 12 Then
MsgBox ("输入月份非法!")
End If
Text2.SetFocus
End Sub
Private Sub text1_KeyPress(KeyAscii As Integer) 'text1:年份输入文本框
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End SubPrivate Sub text2_KeyPress(KeyAscii As Integer) 'text2:月份输入文本框
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
'然后在lostfocus事件中判断:
Private Sub Text1_LostFocus() '判断年份
If Val(Text1) < 1 Or Val(Text1) > 9999 Then
MsgBox ("输入年份非法!")
Text1.SetFocus
End IfEnd SubPrivate Sub Text2_LostFocus() '判断月份
If Val(Text2) < 1 Or Val(Text2) > 12 Then
MsgBox ("输入月份非法!")
Text2.SetFocus
End IfEnd Sub