a = int.Parse(textBox1.Text);
            b = int.Parse(textBox2.Text);
            c = a(int.Parse(comboBox1.Text));
            textBox3.Text = c.ToString();

I am inputing 2 values in a and b ....and through combox1 I am doing calculations

Thanks

Dani AI

Generated

As 's snippet shows, the immediate error comes from trying to "call" an integer variable (as already pointed out). The usual, safe approach is: validate both inputs with TryParse, read which operation the ComboBox contains (for example "+", "-", "*", "/"), perform that operation in a controlled switch or map, check for divide-by-zero, then show the result.

A compact, robust pattern (run from a button click) looks like this:

int a, b;
if (!int.TryParse(textBox1.Text, out a) || !int.TryParse(textBox2.Text, out b)) {
    MessageBox.Show("Enter valid integers.");
    return;
}

string op = comboBox1.SelectedItem as string;
if (string.IsNullOrEmpty(op)) {
    MessageBox.Show("Select an operation.");
    return;
}

int result;
switch (op) {
    case "+":
        result = a + b; break;
    case "-":
        result = a - b; break;
    case "*":
        result = a * b; break;
    case "/":
        if (b == 0) { MessageBox.Show("Cannot divide by zero."); return; }
        result = a / b; break;
    default:
        MessageBox.Show("Unknown operation."); return;
}

textBox3.Text = result.ToString();

Tips and cautions: populate the ComboBox with operator strings (or use SelectedIndex/SelectedValue if you store numeric codes); use double.TryParse if you need fractional results; prefer TryParse to avoid FormatException; run the calculation from a button click or a validated event so empty fields don't cause early parsing; and handle all user errors with friendly messages. See the docs for input parsing and UI properties: int.TryParse, ComboBox.SelectedItem and the C# switch statement.

Recommended Answers

All 2 Replies

a = int.Parse(textBox1.Text);
            b = int.Parse(textBox2.Text);
            c = a(int.Parse(comboBox1.Text));
            textBox3.Text = c.ToString();

I am inputing 2 values in a and b ....and through combox1 I am doing calculations

Thanks

So, what is the question?

Perhaps you better ask your question(if any, see Ana D.) in the C# forum, instead of in the VB.NET forum.
From the code you posted I can see that line 3 will definitly not work.
a is an integer you cannot pass the variable int.Parse(comboBox1.Text) to an integer like you do.
But then again ask the C# forum, more guys and girls over there to solve your problem about C#.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.