0
votes

Im working on a decimal to binary converter that works perfectly on a console and then i get these errors about my core math operations:

System.Windows.Forms.Button does not contain a definition for ToInt32 and no extension method ToInt32 accepting a first argument of type System.Windows.Forms.Button could be found (are you missing a using directive or an assembly reference?) Line:93

No overload for method 'ToString' takes 2 arguments Line:94

System.Windows.Forms.Button does not contain a definition for 'ToInt32' and no extension method 'ToInt32' accepting a first argument of type 'System.Windows.Forms.Button' could be found (are you missing a using directive or an assembly reference?) Line:103

Here is the code:

    public void Convert_Click(object sender, EventArgs e)
    {
        string Input;
        bool IsNotBinary;
        string Answer;
        Start:
        Input = UserInput.Text;
        int InputLength = Input.Length;
        if (InputLength > 10)
        {
            UserInput.Text = "Overflow";
            goto Start;
        }
        int Int;
        bool IsANumber = int.TryParse(Input, out Int);
        if (IsANumber == false)
        {
            UserInput.Text = "Invalid Character";
            goto Start;
        }
        IsNotBinary = Input.Contains("3");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("4");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("5");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("6");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("7");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("8");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("9");
    End:

        if (IsNotBinary == true)
        {

            // decimal to binary
            int InputInt = Convert.ToInt32(Input); // converts the string "Input" to the int "InputInt"
            Answer = Convert.ToString(InputInt, 2);
            UserInput.Text = Answer;

        }

        else
        {

            // binary to decimal
            Answer = Convert.ToInt32(Input, 2).ToString();
            UserInput.Text = Answer;

        }
        Console.ReadLine();
        goto Start;
    }

    public void QuitButton_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }        
}

}

1
Can you show us exactly where this is blowing up? My thoughts are that you've called a button control "Convert" which will throw this off. Changing the name of your button may help. Also: avoid the use of "goto".. there are close to ZERO needs for it and makes the code hard to follow.Simon Whitehead

1 Answers

7
votes

The error message is quite clear:

System.Windows.Forms.Button' does not contain a definition for 'ToInt32'

My psychic debugger tells me that you have a class level button variable named Convert, so you're not calling the ToInt32 method on the static Convert class as your button is hiding it. Either rename the button or fully qualify the name, i.e., System.Convert.ToInt32().

Edit:

Ok, I guess I didn't need my psychic debugger after all. Your event handler tells me all I need to know:

public void Convert_Click(...)