Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 17974
Number of posts: 55343

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Validating TextBox Inputs Posted by HenryCasch on 23 Mar 2012 at 1:59 PM
Hello from Seattle,

I am between beginner and intermediate level in VB.Net 2010. I am trying to validate TextBox input to accept ONLY "A", "a", "S", "s" or the Backspace key. I am missing something and getting a bit frustrated.

My code is:

Private Sub txtAnswer_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _Handles txtAnswer.KeyPress

'Accept only A, a, S, s or Backspace key for "txtAnswer" TextBox Control input
Dim KeyAscii As Integer = Asc(e.KeyChar)

If ((KeyAscii = 8) Or (KeyAscii = 65) Or (KeyAscii = 83) Or (KeyAscii = 97) Or (KeyAscii = 115)) Then
e.Handled = True
KeyAscii = 0
Else
e.Handled = False
End If
End Sub

I am sure a fresh look tomorrow will make the answer pop, but if anyone has the answer, please enlighten me.

Thank you, Henry



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.