如何控制VB6.0的文本框中只能输入某一范围内的数字?
如何控制VB6.0的文本框中只能输入数字?1.只能输入数字,可以由下面的代码实现..
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim Numbers As String
Numbers = "1234567890" + Chr(8) + Chr(46)
If InStr(Numbers, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub
现需要解决下列问题:
2.只能输入一定范围的数字..比如限定只能输入0-65535之间的数字.
3.只能输入特定倍数的数字...比如手机号码,为11位...
应该怎么实现呢??初学,请指点下啊..希望给点具体的代码. 可以在onchange事件中来判断增加的那个字符的ascii码。 Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii > Asc("0") And KeyAscii < Asc("9") Then
If Val(Text1 & Chr(KeyAscii)) > 65535 Then
KeyAscii = 0
End If
Else
' If KeyAscii <> vbKeyBack Then
'
' KeyAscii = 0
' End If
If KeyAscii <> vbKeyBack And KeyAscii <> 13 Then
KeyAscii = 0
End If
End If
End Sub
End Sub 同意楼上的 OK..学习啦.
页:
[1]