Adding up members of an array

1. Junior Member
Join Date
Dec 1969
Posts
19

## Adding up members of an array

Hi there,<BR><BR>always a challenge. I have three different quantities that I need to add up:<BR><BR>qty=session("quantity")<BR> for i=lbound(qty) to ubound(qty)<BR> Response.Write qty(i,1)<BR> next<BR>end sub<BR><BR>The value of the response.write is 548. I need to be able to add 5+4+8. Is this possible? If so, could somebody please help me know how to split these up and add them together to = 17? Any thoughts or comments would be helpful. Thanks so much!<BR><BR>Bennie<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
5,104

## RE: Adding up members of an array

Dim iTotal<BR>Dim sChar<BR><BR>iTotal = 0<BR>For 1 To Len(qty(i, 1))<BR> sChar = Mid(qty(i, 1), 1, 1)<BR> iTotal = iTotal + CInt(sChar)<BR>Next<BR><BR>Response.Write iTotal will be 17.<BR><BR>-Doug

3. Senior Member
Join Date
Dec 1969
Posts
973

## initial guess

Check to see the string is a number, then do a for loop on the string and extract each character and use a clng() on each. Add them up... Any chance the string could represent a negative number?... you may have to handle that case too.

4. Junior Member
Join Date
Dec 1969
Posts
19

## RE: Adding up members of an array

Looks like this is the way to go. thanks a million, Doug!

5. Senior Member
Join Date
Dec 1969
Posts
5,104

http://www.aspmessageboard.com/forum/asp.asp?M=339273&P=1&F=20

6. Junior Member
Join Date
Dec 1969
Posts
19