1个回答
展开全部
注意首先要把text1的MaxLength属性设置为2(最大长度)
Private Sub Text1_Change()
On Error Resume Next
If IsNumeric(Right(Text1.Text, 1)) = False Or IsNumeric(Left(Text1.Text, 1)) = False Or Val(Text1.Text) > 10 Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
If Text1.Text <> "" Then Text1.Text = Val(Text1.Text) '防止十位数输入为0
Text1.SelStart = Len(Text1.Text)
End Sub
以上代码调试通过
Private Sub Text1_Change()
On Error Resume Next
If IsNumeric(Right(Text1.Text, 1)) = False Or IsNumeric(Left(Text1.Text, 1)) = False Or Val(Text1.Text) > 10 Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
If Text1.Text <> "" Then Text1.Text = Val(Text1.Text) '防止十位数输入为0
Text1.SelStart = Len(Text1.Text)
End Sub
以上代码调试通过
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询