Last post Jun 22, 2014 11:05 PM by oned_gk
Jun 22, 2014 08:14 PM|akaubin|LINK
I have multiple check boxes, each are associated with it's own text box, when the checkbox is unchecked, the textbox is not enabled and when it's checked, the text box becomes enabled so the user can enter data into it. But if I run the program with one
or more of the textboxes not enabled (the user didn't need to enter anything in that textbox) I get a "conversion from string "" to type decimal is not valid". I can't figure out how to get around this, I want the program to still run if one or more of the
textboxes aren't enabled
I tried using an If Then statement with textbox1.Text = String.Empty statement but I still received the error.
I'm using visual basic 2012 and I'm very new to this so i've pretty much exhausted my knowledge on what to try. I'd rather not have to remove the checkboxes and just use the textboxes. Any help or ideas would be greatly appreciated.
Jun 22, 2014 08:20 PM|MetalAsp.Net|LINK
Somewhere in your code you're trying to convert a string to a decimal value, yes? At that point, just beforethe conversion, you need to add a null/empty check.
Jun 22, 2014 11:05 PM|oned_gk|LINK
Without If Then, you can do like this
Dim b As Boolean
Dim myDec As Decimal
b = Decimal.TryParse(TextBox1.Text, myDec)
TryParse will try to parse textbox text into myDec, if fail myDec become 0
the tryparse results is true/false indicate the parse fail or success
Whatever text value you will get myDec with decimal value or zero without error