Hello

i need your help in calculating this.

i have 5 textbox with text: N203.00, N40.00, N500.00 .....

how do i add this textbox text and display result on a label.

Thanks
TiM

## All 7 Replies

If all the entries consist of "N" followed by a number you could get the numeric portion by

``````CDbl(txtNumber.Text.Substring(1))
``````

am actually new to programming.. thanks for your comments. i want to know how i can apply them to my code currently i have

``````   label7.text = Val(textbox1.text) + Val(textbox2.text) + Val(textbox3.text) ....
``````

which is not working..

You could do

``````label7.Text = CDbl(textbox1.Text.Substring(1)) _
+ CDbl(textbox2.Text.Substring(1)) _
+ CDbl(textbox3.Text.Substring(1))
``````

etc. This assumes that there are valid values in all of the textboxes. Proper code should do error checking.

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))
End If
Next

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.