Getting numerical input from a masked textbox using VS2005 Visual C++

I am trying to use a function to divide 2 numbers entered into masked textboxs. I have masked the text boxes for 10 numbers.

The masked textbox names are maskedTextBox1 and maskedTextBox2.

Here is my code:

void seti(void)

{

if(maskedTextBox1->Text->Equals("")||maskedTextBox2->Text->Equals(""))

{ //didn't enter everything

MessageBox::Show("You must enter both numbers to proceed.", "!!!Error!!!",

MessageBoxButtons::OK, MessageBoxIcon::Stop);

}

else

{

ckt.i = ((System::Windows::Forms::MaskedTextBox ^(maskedTextBox1->Text))/(System::Windows::Forms::MaskedTextBox ^(maskedTextBox2->Text)));

lblI->Text = ckt.i.ToString();

}

}

This is the error I get:

error C2061: syntax error : identifier 'maskedTextBox1'

Any help is greatly appreciated

Thanks

Rab8712



Answer this question

Getting numerical input from a masked textbox using VS2005 Visual C++

  • Elia Ardizzoni

    Use something like Convert.ToDouble(maskedTextBox1->Text) to get a number from the text. Catch exceptions if the conversion cannot be done. If you don't new floating point results you can also use ToInt32 or ToInt64.

    Here is the basic code without error checking:

    double d = Convert.ToDouble(maskedTextBox1->Text) / Convert.ToDouble(maskedTextBox2->Text);
    lbl->Text = d.ToString();

    --
    SvenC


  • Drake1500

    Thanks SvenC,

    It worked perfectly with 1 exception:

    Convert.ToDouble needed to be Convert::ToDouble

    Rab8712


  • Vesigo

    Correct - changing languages without the compiler looking at it ;)

    --
    SvenC


  • Getting numerical input from a masked textbox using VS2005 Visual C++