Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8048305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:23:28+00:00 2026-06-05T06:23:28+00:00

I tried below code: Private Sub txtName_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtName.KeyPress

  • 0

I tried below code:

 Private Sub txtName_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtName.KeyPress
  ' allow upper and lower case A-Z, and backspace
  If Not Chr(KeyAscii) Like "[A-Za-z]" And KeyAscii <> 8 Then KeyAscii = 0
 End Sub

But it gives:

‘KeyAscii’ is not declared. It may be inaccessible due to its protection level.

Any idea on how to allow alphabet only ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:23:29+00:00Added an answer on June 5, 2026 at 6:23 am

    It looks like you tried to translate a VB6 code verbatim. You need to re-learn the language, VB.NET is completely different in anything but name.

    In your particular case, KeyAscii has been replaced by the KeyPressedEventArgs which has two members: KeyChar and Handled.

    Furthermore, .NET distinguishes between characters and strings (= collection of characters), you cannot simply take a character and apply the Like operator to it, nor should you.

    Instead, do the following:

    If Character.IsLetter(e.KeyChar) Then
        e.Handle = True
    End If
    

    Setting Handled to True has generally the same effect as setting KeyAscii to 0 in VB6 (read the documentation!).

    Furthermore, since you’re obviously just switching, make sure to enable both Option Explicit and Option Strict in the project options, as well as making it the default for further projects in the Visual Studio settings. This helps catching quite a lot of errors for you.

    Finally, this code is bad for usability. It’s generally accepted that fields should not constrain user input in such a way (and it’s also not safe: what if the user uses copy&paste to enter invalid text?). Instead, you should test the validity of the input in the textbox’ Validating event, since it exists this very purpose.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried accessing web for xml parsing using the code below: System.Uri proxy =
I've tried the code below on both Windows (64bit) and Linux(32bit). I was sure
I tried the code below, but it does not work. What's wrong? private void
I tried the below code to check whether my mobile is connected to a
Hi I am new to Erlang and have tried the below code in Pattern
I want to send data through URL.I've tried the below code: Intent browserIntent =
I am just learning Perl's comparison operators. I tried the below code :- $foo=291;
I want to open an xlsx file, I have tried the below code,but neither
I tried using the code below to set up a contextmenu which only displays
I have tried rectifying the code below. But I am not able to find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.