VB高手来啊!急等啊!

来源:百度知道 编辑:UC知道 时间:2024/06/05 04:59:47
怎样判断TEXT中的数字是不是小于5位数!如果大于五位数字就MSGBOX 并删除已输入在TEXT中的数字!

Private Sub Text1_KeyPress(KeyAscii As Integer)
If Len(Text1.Text) >= 5 Then
MsgBox Text1.Text, vbOKOnly, "提示"
Text1.Text = ""
KeyAscii = 0
End If
End Sub

If Len(Text1.Text) >= 5 Then
MsgBox Text1.Text, vbOKOnly, "请重输入"
Text1.Text = ""
Text1.SetFocus
End If

直接设置text 的最大输入长度为5不就行了吗?
maxlength=5