VB的text只能是数字,而且要大于5位,小于10位

来源:百度知道 编辑:UC知道 时间:2024/09/13 04:53:00
VB的text只能是数字,而且要大于等于5位,小于等于10位

Private Sub Form_Load()
Text1.MaxLength = 10
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer) '控制输入的只能是数字
Select Case KeyAscii
Case 48 To 59, 8
Exit Sub
Case Else
KeyAscii = 0
End Select
End Sub

Private Sub Text1_LostFocus() '控制长度
Dim a As Integer
a = Len(Text1)
If a < 5 Or a > 10 Then Text1.SetFocus
End Sub

要在Change事件里判断吧~~

Private Sub Form_Load()
text1.text=""
Text1.MaxLength = 10
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) > 9 And KeyAscii <> 8 Then KeyAscii = 0
End Sub

Private Sub Text1_LostFocus()
If Len(Text1.Text) < 5 Then
Text1.SetFocus
MsgBox "你输入数据的长度小于5,请继续输入"
End If
End Sub