?
Solved

Character Arrays

Posted on 2003-03-13
5
Medium Priority
?
144 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

770 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