VB中如何设定text1中的数据类型
发布网友
发布时间:2022-06-03 03:31
我来回答
共5个回答
热心网友
时间:2023-10-10 18:16
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Len(Text1.Text) <> 0 Then
If KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
ElseIf Len(Text1.Text) = 0 Then
If (KeyAscii >= Asc("a") And KeyAscii <= Asc("z")) _
Or (KeyAscii >= Asc("A") And KeyAscii <= Asc("Z")) _
Or (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) _
Or (KeyAscii = 8) Then
Else
KeyAscii = 0
End If
End If
End Sub
热心网友
时间:2023-10-10 18:16
在text1的keypress事件中处理,每次输入的字符,并且判断当前text1.text中的字符串长度,为0则判断当前输入是否为字符或数字,如果不符合,则返回KeyAscii=0
热心网友
时间:2023-10-10 18:17
Private
Sub
Text1_KeyPress(KeyAscii
As
Integer)
If
Len(Text1.Text)
<>
0
Then
If
KeyAscii
>=
Asc("0")
And
KeyAscii
<=
Asc("9")
Or
KeyAscii
=
8
Then
Else
KeyAscii
=
0
End
If
ElseIf
Len(Text1.Text)
=
0
Then
If
(KeyAscii
>=
Asc("a")
And
KeyAscii
<=
Asc("z"))
_
Or
(KeyAscii
>=
Asc("A")
And
KeyAscii
<=
Asc("Z"))
_
Or
(KeyAscii
>=
Asc("0")
And
KeyAscii
<=
Asc("9"))
_
Or
(KeyAscii
=
8)
Then
Else
KeyAscii
=
0
End
If
End
If
End
Sub
热心网友
时间:2023-10-10 18:17
Private Sub Text1_Changed()
If IsNumeric(Mid(Text1.Text, 2, 1)) = False Then Text1.Text = Mid(Text1.Text, 1, 1)
End Sub
热心网友
时间:2023-10-10 18:18
定义变量之后判断输入支付所在textbox的位置并判断类型