Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
Posted

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.

  • 4 weeks later...
Posted

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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...