Advertisement

05.01.2008 at 03:55PM PDT, ID: 23370337
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

C# display text from textbox in label part 4

Asked by 9apit in Microsoft Visual C#.Net, C# Programming Language

Tags: ,

Hello experts,
Built windows program that takes input from textbox and clicking the Parse button, the program outputs the number of times each letter in the alphabet occurs in the textbox. Case sensitivity is not required.

For example, if the user enters baaad as the text and hits the Parse Button, the result control should display:

There are 3 A's
There are 1 B's
There are 0 C's
There are 1 D's
There are 0 E's
There are 0 F's
etc...

The code compiiles but I get
There are 0 A's
There are 0 B's
There are 0 C's
etc.

Something is wrong with search logic. Thanks. Allen

Code
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace text_from_textbox
{
      
      public class Form1 : System.Windows.Forms.Form
      {
            private System.Windows.Forms.Button button1;
            public System.Windows.Forms.TextBox textBox1;
            private System.Windows.Forms.Label label2;
            private System.Windows.Forms.Label label3;
            public System.Windows.Forms.TextBox textBox2;
      
            private System.ComponentModel.Container components = null;

            public Form1()
            {
                  // Required for Windows Form Designer support
                  InitializeComponent();
            }
            /// Clean up any resources being used.
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if (components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            private void InitializeComponent()
            {
                  this.button1 = new System.Windows.Forms.Button();
                  this.textBox1 = new System.Windows.Forms.TextBox();
                  this.label2 = new System.Windows.Forms.Label();
                  this.label3 = new System.Windows.Forms.Label();
                  this.textBox2 = new System.Windows.Forms.TextBox();
                  this.SuspendLayout();
                  //
                  // button1
                  //
                  this.button1.Location = new System.Drawing.Point(48, 72);
                  this.button1.Name = "button1";
                  this.button1.TabIndex = 0;
                  this.button1.Text = "Parse";
            this.button1.Click += new System.EventHandler(this.button1_Click);
                  //
                  // textBox1
                  //
                  this.textBox1.Location = new System.Drawing.Point(48, 40);
                  this.textBox1.Name = "textBox1";
                  this.textBox1.TabIndex = 1;
                  this.textBox1.Text = "";
                  //
                  // label2
                  //
                  this.label2.Location = new System.Drawing.Point(48, 16);
                  this.label2.Name = "label2";
                  this.label2.Size = new System.Drawing.Size(144, 16);
                  this.label2.TabIndex = 3;
                  this.label2.Text = "Input text to be be parsed";
                  //
                  // label3
                  //
                  this.label3.Location = new System.Drawing.Point(56, 112);
                  this.label3.Name = "label3";
                  this.label3.Size = new System.Drawing.Size(100, 16);
                  this.label3.TabIndex = 4;
                  this.label3.Text = "Parse output";
                  //
                  // textBox2
                  //
                  this.textBox2.Location = new System.Drawing.Point(48, 128);
                  this.textBox2.Multiline = true;
                  this.textBox2.Name = "textBox2";
            this.textBox2.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
                  this.textBox2.Size = new System.Drawing.Size(208, 152);
                  this.textBox2.TabIndex = 5;
                  this.textBox2.Text = "";
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(328, 294);
                  this.Controls.Add(this.textBox2);
                  this.Controls.Add(this.label3);
                  this.Controls.Add(this.label2);
                  this.Controls.Add(this.textBox1);
                  this.Controls.Add(this.button1);
                  this.Name = "Form1";
                  this.Text = "Compare string to input";
                  this.Load += new System.EventHandler(this.Form1_Load);
                  this.ResumeLayout(false);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                  Application.Run(new Form1());
            }

            private void button1_Click(object sender, System.EventArgs e)
            {
                  string s = textBox1.Text;
                  //string s = stringToCheck;
                  string result = "";
 
string[] letters = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
         foreach (string letter in letters)
         {
         string temp = s;
         string lower = letter.ToLower();
         temp.Replace(lower, "");
         temp.Replace(letter, "");
         result += "There are " + (s.Length - temp.Length) + " " + letter + "'s\r\n";
         }
               // put result in a control
      textBox2.Text = result;
      }
        private void Form1_Load(object sender, System.EventArgs e)
      {
              }
       }
}
 Start Free Trial
[+][-]05.01.2008 at 04:24PM PDT, ID: 21483574

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C#.Net, C# Programming Language
Tags: C#, windows
Sign Up Now!
Solution Provided By: rgautier
Participating Experts: 3
Solution Grade: A
 
 
[+][-]05.01.2008 at 04:51PM PDT, ID: 21483695

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.01.2008 at 05:24PM PDT, ID: 21483799

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 06:15PM PDT, ID: 21483948

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080924-EE-VQP-39 / EE_QW_2_20070628