I'm stuck with this problem:
Say i've got a string with "1234" in it, and i need to add up all those numbers (so 1+2+3+4=10). How do I get vb to do that.
I know the answers probably very simple - but Im stuck!
Thanks a lot!
Printable View
I'm stuck with this problem:
Say i've got a string with "1234" in it, and i need to add up all those numbers (so 1+2+3+4=10). How do I get vb to do that.
I know the answers probably very simple - but Im stuck!
Thanks a lot!
Hi
Here is a quick way
VB Code:
Private Sub Command1_Click() Dim MyString As String Dim Counter As Long Dim Total As Long MyString = "1234" 'String to add up Total = 0 'Starting value For Counter = 1 To Len(MyString) 'Loop thru all chars in string (ie 4 chars) Total = Total + CLng(Mid$(MyString, Counter, 1)) 'Add numeric val of each character Next MsgBox Total 'Show total End Sub