在VB文本框中只允许输入5位数字,格式为123.12.如何实现?
发布网友
发布时间:2022-04-25 22:54
我来回答
共2个回答
热心网友
时间:2022-06-18 10:43
对了忘记说了text控件的maxlength属性设置为6 你自己试试吧。没问题的
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case Len(Text1.Text)
Case 0
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
Case 1
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
Case 2
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
Case 3
If KeyAscii = 46 Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
Case 4
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
Case 5
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
End Select
End Sub
Private Sub Text1_Change()
If Val(Text1.Text) >= 1000 Then Text1.Text = Mid(Text1.Text, 2, Len(Text1.Text) - 1)
End Sub
热心网友
时间:2022-06-18 10:44
Private Sub Command1_Click()
Dim 值 As Single
If Len(Text1) <> 6 Then
MsgBox "你输入的位数不对啊"
Exit Sub
End If
值 = Val(Text1)
If 值 >= 1000 Or 值 < 100 Then
MsgBox "你输入的不是三位整数和两位小数啊"
Else
MsgBox "你的输入符合要求"
End If
End Sub
Private Sub Form_Load()
Command1.Caption = "确定"
Text1 = ""
End Sub
答案补充:
为了你这个三维整数难场咋咧!到头来,你却“当我输入完123.12后,然后将最后的一位删掉,将光标移动到小数点前,输入数字”。那你前面说那些干什么?