Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excluding characters from texboxes

Status
Not open for further replies.

bvdv

Programmer
May 20, 2001
4
NL
How do I prevent an error-massage when someone types a character(instead of a figure) in a textbox which is included in a calculation (A = B + text1.text)?
 
Code:
Sub Textbox1_KeyPress (keyascii as integer)
    If KeyAscii = 8 then exit function ' Backspace
    Select Chr(KeyAscii) 
    Case "0", "9"
    Case else 
        keyascii = 0 ' Drop character
    End select
End Sub
 
Oops, make that Case "0" to "9"
And decimal point for kicks.
Code:
Sub Textbox1_KeyPress (keyascii as integer)
    If KeyAscii = 8 then exit function ' Backspace
    Select Chr(KeyAscii) 
    Case "0" to "9"
    Case "."
        if Instr(textbox.text,".") > 0 then
            keyascii = 0 ' Drop character
        End if
    Case else 
        keyascii = 0 ' Drop character
    End select
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top