>I am in a C# class and am having a problem with the Masked TextBox. I must not understand something. The two masked TextBoxes are for the Base Price and the SubTotal. They have the input mask of 999,999.99 foir the base price and 99,999.99 for the SubTotal. I get an error, but it's not even a complete error; it says, "Input string not in correct format." See the lines marked with the double asterisks below (**).
>
>
>//The following line is put ahead of all the below code:
> private decimal decSubTotal = 0M;
>
> private void calculateButton_Click(object sender, EventArgs e)
> {
> string strMessageString;
> //Calculate the cost of the vehicle.
> if (this.basePriceMaskedTextBox.Text != "")
> {
> //Convert from Text to Decimal value.
> ** decSubTotal = decimal.Parse(this.basePriceMaskedTextBox.Text);
> if (this.tradeInAllowanceMaskedTextBox.Text != "")
> {
> decTradeInAllowance =
> ** decimal.Parse(this.tradeInAllowanceMaskedTextBox.Text);
> decSubTotal += decTradeInAllowance;
> this.subTotalLabel.Text = decSubTotal.ToString("C");
> }
> }
> }
>
Cecil,
Textbox doesn't have an InputMask propperty so I assume you use a subclassed textbox. Probably your subclass is already doing a conversion and rendering decimal.Parse useless.
Try with base textbox controls. It works as expected.
Update: Might it be you have currency in your text ($)?
decSubTotal = decimal.Parse (this.basePriceMaskedTextBox.Text,
System.Globalization.NumberStyles.Currency);
Cetin