say im performing addition of two numbers.
there are three textboxes . 2 for entering the numbers and 1 for displaying the result.
im giving one value in first text box and no value in second textbox
it says "conversion not possible". now wat shuld i do to make the value as 0 in a textbox automatically if no value is entered in textbox.
Why are you using a Textbox? Just use a NumericUpDown control with the default set to 0. Not only will this correct your immediate problem, it also saves you all kinds of trouble in verifying that the "values" are actually numeric.
An simpler way, Dim num1 as Double = Val(TextBox1.Text) the Val function returns a double, but if you need it to be an Integer, you can convert it to Integer, Dim num1 as Integer = Convert.ToInt16(Val(TextBox1.Text)) It will convert any string representation of a number to a number, and if the string starts with any non digit character, or is null it will return 0
Or you could use a MaskedTextBox. It allows you to use a format string to restrict what is typed in. Something like "####0.00", will allow any digits to be entered, use the 0 to hard code the format say you want a minimum number of digits, and or decimal places. Use the # to soft code it, to restrict the mamximum number of digits, but not require a minimum. As per my example the user will have to submit at least 3 digits, 2 of them decimnal, but will allow up to 7 digits.