Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Character Arrays

Posted on 2003-03-13
5
Medium Priority
?
150 Views
Last Modified: 2012-05-05
Gurus,

Once again, I need your help.

My VB program needs to receive a string of numbers like these "123434234343".  I need to add all those individual numbers and then display the total.  

Can you please help.

Thanks in advance.

Jorge.
0
Comment
Question by:jorgebot
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
aeklund earned 120 total points
ID: 8131998
Here ya go....

Public Function AddNumbers(ByVal sNumbers As String) As Long
  Dim x, y As Long
 
  For x = 1 To Len(sNumbers)
    y = y + Mid(sNumbers, x, 1)
  Next x
  AddNumbers = y
End Function

MsgBox AddNumbers("123434234343")


You get 36
0
 

Author Comment

by:jorgebot
ID: 8132049
aeklund,

Thanks a lot!

That's exactly what I needed.

Jorge.

0
 
LVL 3

Expert Comment

by:Diveblue
ID: 8132054
minor improvement

Dim x, y As Long
 
 For x = 1 To Len(sNumbers)
   If IsNumeric(Mid(sNumbers, x, 1)) Then
     y = y + Mid(sNumbers, x, 1)
   Else
     MsgBox "String contains a non-numeric value!!"
     Exit Sub
   End If
 Next x
 AddNumbers = y
0
 
LVL 10

Expert Comment

by:aeklund
ID: 8132063
Your welcome.
0
 

Author Comment

by:jorgebot
ID: 8132340
Thanks Diveblue
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question