Drstein99 Posted April 26, 2004 Posted April 26, 2004 PLEASE POST REPLIES IN VB.NET SYNTAX ONLY I'm using keypress event, to trigger validation: Public Sub esKeyPressInteger(ByVal sender As Object, ByVal e As KeyPressEventArgs) and the VALUE of keys.delete (46) IS the same ASCII value of the ascii code for "." (decimal point) How do i figure out that the char entered is only numeric, and also allow a delete or arrow key? I'm using this and it's malfunctioning: If (Char.IsNumber(e.KeyChar) Or Asc(e.KeyChar) = Keys.Delete Or Asc(e.KeyChar) = Keys.Back) AND ASC(E.KeyChar) <> KEYS.Decimal Then e.Handled = False Else e.Handled = True End If Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
JABE Posted April 27, 2004 Posted April 27, 2004 Try this: Dim m_blnKeyHandled As Boolean Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown m_blnKeyHandled = e.KeyCode = Keys.Decimal OrElse _ e.KeyCode = Keys.Back OrElse _ e.KeyCode = Keys.Delete OrElse _ Char.IsLetter(Convert.ToChar(e.KeyValue)) End Sub Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress e.Handled = m_blnKeyHandled End Sub Btw, I hope you're aware that a NumericUpDown control exists, specifically designed to accept numeric input. Quote
ThePentiumGuy Posted May 22, 2004 Posted May 22, 2004 hey a quick question, whta's OrElse do?, tahnks in response to the first post, If (e.keycode = keys.Back Or e.keycode = keys.Delete Then 'do the same for the numbers(ex: keys.1 though 9 i beleive) or maybe "Or Char.IsNumber(e.keycode)" would work 'here you'd type in code that executes when you push thoe keys end if Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Administrators PlausiblyDamp Posted May 22, 2004 Administrators Posted May 22, 2004 Or else only evaluates both operands if the first is false - otherwise it knows if the first is true it doesn't matter what the second operand equates to. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
ThePentiumGuy Posted May 23, 2004 Posted May 23, 2004 ah i see. thanks a lot , pent Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.