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 8191839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:00:45+00:00 2026-06-07T04:00:45+00:00

I am writing a program to communicate over the serial port. All data that

  • 0

I am writing a program to communicate over the serial port. All data that is sent is mirrored back. Everything works fine except backspaces. When I hit the backspace button the only way I know how to remove the last character in the text box is to use a mid function then overwrite the current data with the new data. When a lot of data is inside the richtextbox it starts to flicker. I have tried using the richtextbox.text.remove function but I get this error. “Index and count must refer to a location within the string. Parameter name: count”

RichTextBox1.Text.Remove(RichTextBox1.TextLength, 1)

I have tried to throw some number into the function that does not cause it to error out but no data is removed from the richtextbox.

Here is the code that transmits data

   KeyCharString = e.KeyChar 'stores key being pressed into KeyCharString
    Try
        SerialPort1.Write(KeyCharString) 'tx data for key being pressed
    Catch ex As Exception
        MsgBox(ex.Message) 'Displays error if serialport1 cannot be written to
    End Try

    If Asc(KeyCharString) = 8 Then 'If char is a backspace remove precious character and exit sub
        RichTextBox1.Text = RichTextBox1.Text.Remove(RichTextBox1.TextLength, 1)
        'RichTextBox1.Text = Mid(RichTextBox1.Text, 1, RichTextBox1.TextLength - 1)'Old code used to remove the character.  Causes the richtextbox to flicker when rewriting the data
        Exit Sub
    End If

This is the code that receives data

    receivedString = SerialPort1.ReadExisting.ToString

    If Asc(receivedString) = 8 Then 'deletes the received data if it is a backspace
        receivedString = ""
        Exit Sub
    End If
    RichTextBox1.AppendText(receivedString) 'adds new data to the richtextbox

Is there a way to remove 1 character from the richtextbox without rewriting all the data inside it? Also, the richtextbox is read 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-07T04:00:47+00:00Added an answer on June 7, 2026 at 4:00 am

    The String.Remove method that you are using returns a String it does not do anything with the original string.

    from MSDN Link:

    Returns a new string in which all the characters in the current instance, beginning at a specified position and continuing through the last position, have been deleted.

    Try this but I am not sure of the flicker:

    RichTextBox1.Text = RichTextBox1.Text.Remove(RichTextBox1.TextLength - 1, 1)
    

    or something like this:

    RichTextBox1.SelectionStart = RichTextBox1.TextLength - 1
    RichTextBox1.SelectionLength = 1
    RichTextBox1.ReadOnly = False
    RichTextBox1.SelectedText = ""
    RichTextBox1.ReadOnly = True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a program that must communicate with a PHP / web based
I am writing a program that uses Lua socket to communicate with a http
I'm writing simple program to communicate between smart devices and I receive 11001 when
I'm writing a program to communicate with certain patient monitor using connection-less (UDP) sockets.
I'm writing a client application to communicate with a server program via UDP. The
Im writing a program that should read input via stdin, so I have the
I'm writing a program that handles DBs and writes any changes into ListView for
I am currently writing a program using Weka that builds a model (using one
I'm writing a program that's parsing an XML file to java objects using smooks.
I am writing a program that needs to read a set of records that

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.