Thanks Alot Jim, what if some of the textbox is empty? that is if some or one textbox doesnot contain any value i want to always calculate to get the total of textboxes with value out of all the textboxes.
Then you might consider putting all of the textboxes into a GroupBox and doing the following
Dim sum As Double = 0.0
For Each tbx As TextBox In GroupBox1.Controls.OfType(Of TextBox)()
If tbx.Text <> "" AndAlso IsNumeric(tbx.Text.Substring(1)) Then
sum += CDbl(tbx.Text.Substring(1))
MsgBox("sum is " & sum)
In the validation code for each textbox, make sure the text is well-formed. If it is, store the value in a module-level private Integer value. If not, cancel the validation, forcing the user to enter a valid value. Allow an empty field, which loads the module-level variable with 0. In the end, just add up all the module-level variables and display the result.