Cricinfo Live Scores

Saturday, March 29, 2008

Restrict Keys in vba textbox

Hi, when i went to work out with my VBA application then i faced a problem of restricting
key press in my price textbox. So, i went on searching and searching in the internet. And
at last found a solution to it. Take a look on it.

Private Sub txtMasterPrice_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc("0") To Asc("9")
Case Asc("-")
If InStr(1, txtMasterPrice.Text, "-") > 0 Or txtMasterPrice.SelStart > 0 Then
KeyAscii = 0
End If
Case Asc(".")
If InStr(1, txtMasterPrice.Text, ".") > 0 Then
KeyAscii = 0
End If
Case Else
KeyAscii = 0
End Select
End Sub