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

  • Home
  • SEARCH
  • 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 617709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:27:55+00:00 2026-05-13T18:27:55+00:00

For example I only the second character in each line to be an x,

  • 0

For example I only the second character in each line to be an x, while the 3nd to 10th character must be a hex digit.
At the moment I use a Select Case, then check the position of the caret (using textbox.selectionstart) and see if the key being pressed is a “legal” character.

Is there a better way of doing this as it slows down on large amounts of text.

This is the code I have at the moment:

 Select Case TextBox1.SelectionStart
     Case TextBox1.GetFirstCharIndexOfCurrentLine + 1 
         If Not e.KeyChar = "x" Then
             e.Handled = True
         End If
     Case (TextBox1.GetFirstCharIndexOfCurrentLine + 2) To (TextBox1.GetFirstCharIndexOfCurrentLine + 9) 
         Dim allowedchars As String = "abcdefABCDEF0123456789" & vbCrLf & Chr(Keys.Back)
         If allowedchars.Contains(e.KeyChar) Then
             e.Handled = False
         Else
             e.Handled = True
         End If
 End Select
  • 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-05-13T18:27:55+00:00Added an answer on May 13, 2026 at 6:27 pm

    You say it slows down on large amounts of text; maybe it’s the TextBox1.GetFirstCharIndexOfCurrentLine call that takes longer with large amounts of text. You call it three times, but you could only call it once:

    Dim firstChar As Integer = TextBox1.GetFirstCharIndexOfCurrentLine()
    
    Select Case TextBox1.SelectionStart
        Case firstChar + 1 
            ...
        Case firstChar + 2 To firstChar + 9
            ...
     End Select
    

    Code looks cleaner too!

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

Sidebar

Ask A Question

Stats

  • Questions 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • added an answer Well, start off by thinking of which bits of data… May 17, 2026 at 9:17 am
  • added an answer For this task it is a good idea to use… May 17, 2026 at 9:15 am
  • added an answer This is exactly how the Skyhook database (built into many… May 17, 2026 at 9:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.