By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,870 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,870 IT Pros & Developers. It's quick & easy.

Ascii Values Of String

P: 20
hi all

i have a string
<cr><lf>999,1.52,32.85,5.91,15.81,1.39,26.17,15.75 ,12.3
want to calculate its ASCII values sum which is equal to 2411.How can i calculate ascii sum of all the string values.

thanks in advance
Oct 18 '06 #1
Share this Question
Share on Google+
1 Reply


Expert 5K+
P: 8,434
hi all

i have a string
<cr><lf>999,1.52,32.85,5.91,15.81,1.39,26.17,15.75 ,12.3
want to calculate its ASCII values sum which is equal to 2411.How can i calculate ascii sum of all the string values.

thanks in advance
For a start, how are you counting? I tried it and got either 2367 or 3011, depending on whether I converted the "<cr><lf>" to carriage return (13) and linefeed (10) characters or not. Are you skipping the commas? Do you have trailing blanks that are included in the count?

Um...

Ok, I tried adding up the values of the actual numbers (first 999, then 1.52, and so on) and got 1110.7. So I still don't get it.
If it's any help, here's the routine I wrote to try it out. This was under VB6, and I just created a new project with one form.
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. DefLng A-Z
  3. Private Sub Form_Click()
  4.   Dim s As String
  5.   Dim TempNum As String, Char As String * 1
  6.   Dim I As Long, T As Long, T2 As Single
  7.  
  8.   's = vbCrLf & "999,1.52,32.85,5.91,15.81,1.39,26.17,15.75,12.3"
  9.   s = "<cr><lf>999,1.52,32.85,5.91,15.81,1.39,26.17,15.75,12.3"
  10.   For I = 1 To Len(s)
  11.     Char = Mid$(s, I, 1)
  12.     T = T + Asc(Char)
  13.     Debug.Print Asc(Char), T
  14.   Next
  15.   Debug.Print "Method 1: "; T
  16.  
  17.   For I = 1 To Len(s)
  18.     Char = Mid$(s, I, 1)
  19.     Select Case Char
  20.       Case "0" To "9", "."
  21.         TempNum = TempNum & Char
  22.       Case Else
  23.         T2 = T2 + Val(TempNum)
  24.         Debug.Print TempNum, T2
  25.         TempNum = ""
  26.     End Select
  27.   Next
  28.   T2 = T2 + Val(TempNum)
  29.   Debug.Print "Method 2: "; T2
  30. End Sub
Here's what it displayed...
Expand|Select|Wrap|Line Numbers
  1.  49            2864 
  2.  50            2914 
  3.  46            2960 
  4.  51            3011 
  5. Method 1:  3011 
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. 999            999 
  15. 1.52           1000.52 
  16. 32.85          1033.37 
  17. 5.91           1039.28 
  18. 15.81          1055.09 
  19. 1.39           1056.48 
  20. 26.17          1082.65 
  21. 15.75          1098.4 
  22. Method 2:  1110.7 
  23.  
Oct 24 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.