我在vb中的text的keypress中对以下应如何处理呀(略去非数字字符的输入)
Private Sub txtBom_KeyPress(KeyAscii As Integer)
If KeyAscii < 49 And KeyAscii > 57 Then
××××××××××××
End If
End Sub
谢谢了!
...全文
26615打赏收藏
小妹子请问在vb中的text中如何限制非数字的输入?(一个极弱智的问题啦)
我在vb中的text的keypress中对以下应如何处理呀(略去非数字字符的输入) Private Sub txtBom_KeyPress(KeyAscii As Integer) If KeyAscii 57 Then ×××××××××××× End If End Sub 谢谢了!
Private Function confineinput(para_keyascii As Integer, para_confinestr As String)
Dim sconfinestr As String
sconfinestr = UCase(para_confinestr) + Chr(13) + Chr(8) + Chr(27)
If InStr(1, sconfinestr, UCase(Chr(para_keyascii)), vbTextCompare) = 0 Then
confineinput = 0
Else
confineinput = para_keyascii
End If
End Function
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = confineinput(KeyAscii, "1234567890")
End Sub
楼上-荷船-对,补充点
private sub text1_keypress(keyascii as integer)
if keyascii=8 then exit sub '退格
if keyascii=13 then
XXXXXXXXXXX '回车,通常调用过程。commandX_click
end if
if keyascii=asc(".") then exit sub '别忘了小数点哦~~
if keyascii=asc("-") then exit sub '负数啦!
if keyascii< asc("0") or keyascii > asc("9") then keyascii=0
end sub
Private Sub txtBom_KeyPress(KeyAscii As Integer)
If KeyAscii < 49 Or KeyAscii > 57 Then
txtbom.Locked = True
Else
If txtbom.Locked = True Then
txtbom.Locked = False
txtbom = txtbom & Chr(KeyAscii)
txtbom.SelStart = Len(txtbom.Text)
End If
End If
End Sub
这个一定没问题,我试过了。
以下给出标准例程:
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
KeyAscii = FilterWhole(KeyAscii)
End Sub
Public Function FilterWhole(ByVal KeyAscii As Integer) As Integer
If (KeyAscii <> vbKeyDelete) And (KeyAscii <> vbKeyBack) _
And (KeyAscii < 48 Or KeyAscii > 57) Then
KeyAscii = 0
End If
FilterWhole = KeyAscii
End Function
Public Function sffunLimitNumber(ByVal IntVal As Integer) As Integer
'-------------------1-------------------
'目 的:只允许在文本框内输入数字、退格、删除及回车键
'输 入:ByVal IntVal As Integer,任意的键值
'被传递值:无
'返 回 值:过滤后的键值
'输 出:无
'注 解:
'用 法:在文本框的KeyPress事件中输入KeyAscii = sffunLimitNumber(KeyAscii)即可
'修 订 版:
'-------------------1-------------------
If (IntVal <> vbKeyDelete) _
And (IntVal <> vbKeyBack) _
And (IntVal <> 13) _
And (IntVal < 48 Or IntVal > 57) Then
IntVal = 0
End If
sffunLimitNumber = IntVal