10 Replies - 3159 Views - Last Post: 20 March 2010 - 07:07 AM Rate Topic: -----

#1 fringe4life  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-March 10

Why won't it display in the rich text box

Posted 19 March 2010 - 03:08 AM

 private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int weight, height, BMI;
                weight = int.Parse(textbox1.Text);
                height = int.Parse(textbox2.Text);
                BMI = int.Parse(richtextbox1.Text);
                BMI = (weight) / (height ^ 2);
                
                if (BMI < 18.5)
                    richtextbox1.Text = (BMI + ("Your are Underweight") + ("Height =" + height +("m") + ("Weight =" + weight + ("Kg")))); 
                else if (18.5 < BMI && BMI < 24.9)
                    richtextbox1.Text = (BMI + ("Your are a Normal Weight") + ("Height =" + height + ("m") + ("Weight =" + weight + ("Kg"))));
                else if (BMI > 25)
                    richtextbox1.Text = (BMI + ("Your are Over Weight") + ("Height =" + height + ("m") + ("Weight =" + weight + ("Kg"))));
                else if (BMI < 0)
                {
                   MessageBox.Show("Error Must Only Input Numeric Data i.e '0-9'");
                   return;
                }
            }
            catch {} //To catch if any non numeric values have been typed into height, weight
        }
    }

why won't any text display in the richtext box when i run my program??? There are no reported errors
ive tried richtextbox1.AppendText(BMI + ("Your are Underweight") + ("Height =" + height +("m") + ("Weight =" + weight + ("Kg"))); which also failed to display a result int the richtextbox.

This post has been edited by fringe4life: 19 March 2010 - 05:48 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Why won't it display in the rich text box

#2 beju0506  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 78
  • Joined: 23-February 08

Re: Why won't it display in the rich text box

Posted 19 March 2010 - 04:21 AM

I'm a bit new to C# myself, but I think you have to set the "Text" property:


myRichTextBox.Text = "Here's some content";




I may be wrong though; I don't have the IDE open right now...
Hope that helps!
Was This Post Helpful? 1
  • +
  • -

#3 b.ihde  Icon User is offline

  • D.I.C for life
  • member icon

Reputation: 44
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Re: Why won't it display in the rich text box

Posted 19 March 2010 - 04:27 AM

Hello fringe4life!

At first: PLEASE use our code tags like this -> [ c o d e ] post code here [ / c o d e ] (without spaces of course)

And yes, beju is right, it should be richtextbox1.Text :)

Greetz

ben
Was This Post Helpful? 0
  • +
  • -

#4 fringe4life  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-March 10

Re: Why won't it display in the rich text box

Posted 19 March 2010 - 04:27 AM

I tried that just now and still no luck. Thanks for trying though.
It now says FormatException Was Unhandled.

This post has been edited by fringe4life: 19 March 2010 - 04:45 AM

Was This Post Helpful? 0
  • +
  • -

#5 EtherealMonkey  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 33
  • Joined: 17-March 10

Re: Why won't it display in the rich text box

Posted 19 March 2010 - 05:13 AM

View Postfringe4life, on 19 March 2010 - 02:08 AM, said:

 private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int weight, height, BMI;
                weight = int.Parse(textbox1.Text);
                height = int.Parse(textbox2.Text);
                BMI = int.Parse(richtextbox1.Text);
                BMI = (weight) / (height ^ 2);
                
                if (BMI < 18.5)
                    richtextbox1.Text = (BMI + ("Your are Underweight") + ("Height =" + height +("m") + ("Weight =" + weight + ("Kg")))); 
                else if (18.5 < BMI && BMI < 24.9)
                    richtextbox1.Text = (BMI + ("Your are a Normal Weight") + ("Height =" + height + ("m") + ("Weight =" + weight + ("Kg"))));
                else if (BMI > 25)
                    richtextbox1.Text = (BMI + ("Your are Over Weight") + ("Height =" + height + ("m") + ("Weight =" + weight + ("Kg"))));
                else if (BMI < 0)
                {
                   MessageBox.Show("Error Must Only Input Numeric Data i.e '0-9'");
                   return;
                }
            }
            catch {} //To catch if any non numeric values have been typed into height, weight
        }
    }

why won't any text display in the richtext box when i run my program??? There are no reported errors
ive tried richtextbox1.AppendText(BMI + ("Your are Underweight") + ("Height =" + height +("m") + ("Weight =" + weight + ("Kg"))); which also failed to display a result int the richtextbox.


try:

richtextbox1.Text = (BMI.ToString() + "Your are Underweight" + "Height =" + height.ToString() +"m" + "Weight =" + weight.ToString() + "Kg")



Or, I would rather do the int.Parse(string) when I was using the values in a situation like this - YMMV.

HTH

This post has been edited by EtherealMonkey: 19 March 2010 - 05:15 AM

Was This Post Helpful? 1
  • +
  • -

#6 Zdrenka  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 116
  • Joined: 24-November 09

Re: Why won't it display in the rich text box

Posted 19 March 2010 - 05:32 AM

sorry just realise my answers doesn't work..

This post has been edited by Zdrenka: 19 March 2010 - 05:34 AM

Was This Post Helpful? 0
  • +
  • -

#7 fringe4life  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-March 10

Re: Why won't it display in the rich text box

Posted 19 March 2010 - 05:46 AM

I changed it to that but now theres,
BMI = int.Parse(richtextbox1.Text);

is FormatException is Unhandled. Input string was not in a correct format.
Any Ideas??
Nevermind i just deleted it... Thanks Ethereal Monkey and Beju.

This post has been edited by fringe4life: 19 March 2010 - 07:43 AM

Was This Post Helpful? 0
  • +
  • -

#8 Bent al-Yemen  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 106
  • Joined: 30-December 09

Re: Why won't it display in the rich text box

Posted 19 March 2010 - 09:09 AM

this one worked :
using System;
 

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int weight, height, BMI;
                weight = int.Parse(textBox1.Text);
                height = int.Parse(textBox2.Text);
               // BMI = int.Parse(richTextBox1.Text);
                BMI = (weight) / (height ^ 2);

                if (BMI < 18.5)
                    richTextBox1.Text = BMI + ("Your are Underweight") + ("Height =" + height + ("m") + ("Weight =" + weight + ("Kg")))+"\n";
                else if (18.5 < BMI && BMI < 24.9)
                    richTextBox1.Text = BMI + ("Your are a Normal Weight") + ("Height =" + height + ("m") + ("Weight =" + weight + ("Kg")));
                else if (BMI > 25)
                    richTextBox1.Text = BMI + ("Your are Over Weight") + ("Height =" + height + ("m") + ("Weight =" + weight + ("Kg")));
                else if (BMI < 0)
                {
                    MessageBox.Show("Error Must Only Input Numeric Data i.e '0-9'");
                    return;
                }
            }
            catch { } //To catch if any non numeric values have been typed into height, weight
        }

         
    }
 


i didn't know what do u mean by this statement :
 // BMI = int.Parse(richTextBox1.Text);


another thing , the equation is not reasonable . So, every time you'll get " you're underweight".

This post has been edited by Bent al-Yemen: 19 March 2010 - 09:26 AM

Was This Post Helpful? 0
  • +
  • -

#9 fringe4life  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-March 10

Re: Why won't it display in the rich text box

Posted 20 March 2010 - 05:00 AM

Yes i have since also changed height and weight to being double instead of int. and reworked my code to look like this
         private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                double weight, height, BMI;
                weight = double.Parse(textbox1.Text);
                height = double.Parse(textbox2.Text);
                BMI = (weight) / (height * height);



                if (BMI > 0 && BMI < 18.5)
                {
                    richtextbox1.Text = ((BMI.ToString(("#.##")) + " You're Underweight") + Environment.NewLine + ("Height =" + height.ToString() + "m" + " Weight =" + weight.ToString() + "Kg"));
                }
                else if (18.5 < BMI && BMI < 24.9)
                {
                    richtextbox1.Text = ((BMI.ToString(("#.##")) + " You're a Normal Weight") + Environment.NewLine + (("Height =" + height.ToString() + "m") + Environment.NewLine + ("Weight =" + weight.ToString() + "Kg")));
                }
                else if (BMI > 25)
                {
                    richtextbox1.Text = ((BMI.ToString(("#.##")) + " You're over Weight") + Environment.NewLine + (("Height =" + height.ToString() + "m") + Environment.NewLine + ("Weight =" + weight.ToString() + "Kg")));
                }
                else if (BMI < 0)
                {
                    MessageBox.Show("Error Must Only Input Numeric Data i.e '0-9'");
                    return;
                }
            }
            catch { }
        }
     }
}


But my latest problem is catching any non-numeric data entered into the 2 textbox's

This post has been edited by fringe4life: 20 March 2010 - 05:16 AM

Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,661
  • Joined: 23-August 08

Re: Why won't it display in the rich text box

Posted 20 March 2010 - 05:45 AM

Look into the TryParse() methods for error-checking of user input.
Was This Post Helpful? 0
  • +
  • -

#11 fringe4life  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 15-March 10

Re: Why won't it display in the rich text box

Posted 20 March 2010 - 07:07 AM

try parse isn't working because it is the name TryParse 'Does not exist in the current context'
so i figured i would try this with i posted above
catch
            {
                Convert.ToString(textbox1.Text);
                MessageBox.Show("Error Must Only Input Numeric Data into Height textbox");
                Convert.ToString(textbox2.Text);
                MessageBox.Show("Error Must Only Input Numeric Data into Weight textbox");
                return;
            }



which works. thanks for your help everyone.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1