none
Error compiling: double does not contain a definition for Text

    Question

  • Here is my code. What does it not work? Very new to this, in college. Thank you for any help.

    I have not finished the program yet. The error it keeps giving me states: 'double' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'double' could be found (are you missing a using directive or an assembly reference?)

    using

    System;


    using

    System.Collections.Generic;


    using

    System.ComponentModel;


    using

    System.Data;


    using

    System.Drawing;


    using

    System.Linq;


    using

    System.Text;


    using

    System.Windows.Forms;



    namespace

    Temperature_Conversion

    {

       

    publicpartialclassForm1: Form


        {

           

    publicForm1()

            {

                InitializeComponent();

            }

           

    privatevoidclearButton_Click(objectsender, EventArgse)

            {

               

    // Clear the text boxes.


                textBox1.Text =

    ""; textBox2.Text = "";

            }

           

    privatevoidexitButton_Click(objectsender, EventArgse)

            {

               

    // Close the form.


               

    this.Close();

            }

           

           

    privatevoidbutton1_Click(objectsender, EventArgse)

            {

               

    doubletextBox2 = double.Parse(textBox2.Text);

               

    doubletotal = textBox2 * 9 / 5 + 32;

                label2.Text =

    "The temperature in Fahrenheit is: "+ textBox2.ToString("F");

            }

           

    privatevoidlabel1_Click(objectsender, EventArgse)

            {

            }

           

    privatevoidlabel2_Click(objectsender, EventArgse)

            {

            }

           

    privatevoidtextBox2_TextChanged(objectsender, EventArgse)

            {

               

            }

           

    privatevoidtextBox1_TextChanged(objectsender, EventArgse)

            {

               

            }

           

    privatevoidbutton2_Click(objectsender, EventArgse)

            {

               

    doubletextBox1 = double.Parse(textBox1.Text);

               

    doubletotal = (textBox1 - 32) * 5 / 9;

                label1.Text =

    "The temperature in Celsius is: "+ textBox1.ToString("C");

            }

           

        }

    }


    Wednesday, October 30, 2013 6:21 AM

Answers

  • Hi,

    I don't know why you use

    double textBox1 = double.parse

     Okay, let's see how to deal with this problem.

            private void button1_Click(object sender, EventArgs e)
            {
                double textBox1 = double.Parse(this.textBox1.Text);
                
                double total = (textBox1 - 32) * 8 / 5;
                MessageBox.Show( textBox1.ToString("C"));
            }

    The above code works well. Do you know what? Because when you use textBox1.Text, the 'textBox1' is just a local variable, and its type is 'double'. 


    Every answer may help a lot, thanks guys
    Frank

    • Marked as answer by Mitch Hean Sunday, November 03, 2013 8:20 AM
    Thursday, October 31, 2013 7:24 AM