VB中如何设定text1中的数据类型
6个回答
展开全部
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
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
展开全部
在text1的keypress事件中处理,每次输入的字符,并且判断当前text1.text中的字符串长度,为0则判断当前输入是否为字符或数字,如果不符合,则返回KeyAscii=0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Text1_Changed()
If IsNumeric(Mid(Text1.Text, 2, 1)) = False Then Text1.Text = Mid(Text1.Text, 1, 1)
End Sub
If IsNumeric(Mid(Text1.Text, 2, 1)) = False Then Text1.Text = Mid(Text1.Text, 1, 1)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
定义变量之后判断输入支付所在textbox的位置并判断类型
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询