adding function

nsilpa

New member
Joined
Jun 27, 2008
Messages
1
Programming Experience
Beginner
hi experts,

i learning .net,i had query in windows application(VB.Net) i.e., i had one text box,in which i can enter n numbers. i had display sum of the numbers by using button action.

eg:- i am entering values like this 1,2,3,4,5,........... in text box and by clciking on button(add) it should display sum of the numbers in pop-up
 
What you need to do is split the string on the comma "," which will then give you a string array of the numbers. Then loop through the array adding them all up and there's your answer.

VB.NET:
    Private Function Math_Add(ByVal Text As String) As Decimal
        Dim Pieces() As String = Text.Split(","c)
        Dim RetVal As Decimal
        For Counter As Integer = 0 To Pieces.GetUpperBound(0)
            RetVal += CDec(Pieces(Counter))
        Next Counter
        Return RetVal
    End Function
 
Back
Top