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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:47:41+00:00 2026-05-27T02:47:41+00:00

I have this program that is reading the test string from a textbox and

  • 0

I have this program that is reading the test string from a textbox and convert it to a byte array that makeup data to be diplayed on a screen. I am getting very close. The code can currently pull the text, convert it to a char array, and then replace the zeros in the byte array with useful data from a 2 dimensional array that contains 5 bits for all the letters of the alphabet. I am have a problem though. The code only seems to run once. If I click the button a second time I end up with an “indexOutOfRange exception unhandled.” Also it only seems to work for one letter at a time

EX: if I type “A” it will display, but if I type “AA” I get the same error.
Here is the WordArray[]

byte[,] Letters = new byte[18, 5] { { 63, 72, 72, 63, 0 },
                                       { 127, 73, 73, 54, 0 },
                                       { 63, 72, 72, 63, 0 },
                                       { 127, 73, 73, 54, 0 },
                                       { 63, 72, 72, 63, 0 },
                                       { 127, 73, 73, 54, 0 }, 
                                       { 63, 72, 72, 63, 0 },
                                       { 127, 73, 73, 54, 0 }, 
                                       { 63, 72, 72, 63, 0 }, 
                                       { 127, 73, 73, 54, 0 },
                                       { 63, 72, 72, 63, 0 },
                                       { 127, 73, 73, 54, 0 },
                                       { 63, 72, 72, 63, 0 },
                                       { 127, 73, 73, 54, 0 }, 
                                       { 63, 72, 72, 63, 0 },
                                       { 127, 73, 73, 54, 0 },
                                       { 63, 72, 72, 63, 0 },
                                       { 127, 73, 73, 54, 0 } };

Here is the click_button method:

    int Aindex = 0;
    int LettersIndex = 0;
    private void SendButton_Click(object sender, EventArgs e)
    {
        WordIndex = 0;
        if (Aindex > 0)
        {
            Aindex = 0;
        }
        string CurrentTextString = textBox1.Text;
        char[] charArray = CurrentTextString.ToCharArray();
        if (textBox1.Text == "")
        {

        }
        else
        {
            foreach (char c in charArray)
            {
                int index = 0;
                CharAsciiArray[index] = Convert.ToChar((Convert.ToInt32(c)));
                textBox2.Text += CharAsciiArray[index] + " ";
                charCount++;
                index++;
            }
            for (int NumberofBytes = 0; NumberofBytes < charCount; NumberofBytes++)
            {

                LettersIndex = 0;
                // int currentChar = CharAsciiArray[index] - 65;
                //textBox2.Text += currentChar;
                int currentCharAscii = (CharAsciiArray[Aindex]);
                int currentChar = currentCharAscii - 'A';
                for (int NumberofBits = 0; NumberofBits < 5; NumberofBits++)
                {


                    // textBox2.Text += currentChar;
                    WordArray[WordIndex + 3] = Letters[currentChar, LettersIndex];
                    textBox2.Text += WordArray[WordIndex] + " ";
                    LettersIndex++;
                    WordIndex++;
                }
                Aindex++;
            }
            SendingData = true;
            //SendNextByte();

            serialPort1.Write(WordArray, 0, WordArray.Length);
        }
    }
  • 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-27T02:47:41+00:00Added an answer on May 27, 2026 at 2:47 am

    In the following loop

      foreach (char c in charArray)
      {
          int index = 0;
          CharAsciiArray[index] = Convert.ToChar((Convert.ToInt32(c)));
          textBox2.Text += CharAsciiArray[index] + " ";
          charCount++;
          index++;
      }
    

    You apparently want to increase the index on each iteration but you’re resetting index to 0 every time.

    Besides that, make up your mind on what pattern you want to follow when naming your variables. For instance:

    Why is AIndex not AnIndex and how would you name the next index? AnotherIndex? Does it need to be global? Why does charArray start with a lowercase c and NumberOfBytes with an uppercase N? Write code as if you would have to explain it to your wife / husband (who knows?) and it’ll be easier to maintain / debug.

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

Sidebar

Related Questions

This is a test program that I have written for a larger project that
I have this program that should execute a piece of code base on the
So I have this program that I really like, and it doesn't support Applescript.
I have a C/ncurses program that I'm debugging/maintaining. This program does ripoffline twice: first,
I have a program that looks something like this: public partial class It {
I have a program that simulates mouse click. Code is something like this: [DllImport(user32.dll,
I have a program that generates a .shp file, and exports this as a
I have written a program that uses qhttp to get a webpage. This works
I have an executable that is started by a windows service, this program will
This is my problem. I have a program that has to run in a

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.