Link to home
Start Free TrialLog in
Avatar of gsp007
gsp007

asked on

there are A-Z alphabets which are numbered as 1-26 .

if i eter any word , i should get known that which letter is in that word & for how many times.
then i should also get the total of the corresponding numbers to these characters & to display the full
total. so can you give the solution (with coding)?
ASKER CERTIFIED SOLUTION
Avatar of hongjun
hongjun
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RavenOfThought
RavenOfThought

If you ONLY need the total of the letter-counts, that would equal the amount of letters in the word. o_O
To display the full total you would simply need to say:
Msgbox Len(strWord)

If you NEED the other letter counts, use hongjun's code :-P
A modification to my above code to get full total.

Private Sub Command1_Click()
   Dim alphabet(26) As Integer
   Dim intTotal As Integer
   Dim i As Integer
   Dim character As String
   
   intTotal = 0
   For i = 1 To Len(Text1.Text)
       character = UCase(Mid(Text1.Text, i, 1))
       If character >= "A" And character < "Z" Then
           alphabet(Asc(character) - 64) = alphabet(Asc(character) - 64) + 1
           intTotal = intTotal + 1
       End If
   Next
   
   ' display count
   For i = 1 To 26
       Debug.Print Chr(i + 64) & ": " & alphabet(i)
   Next

   Debug.Print "Full Total = " & intTotal
End Sub

Private Sub Form_Load()
   Text1.Text = ""
End Sub


hongjun
Note that the use of Len(strWord) to get full total is not reliable because a non-alphabet can be entered.

hongjun
Just a small observation, but I think that should that be a '<=' not a '<'

If character >= "A" And character <= "Z" Then


-Z-
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
/me bets this guy isn't ever coming back
Same thoughts. Perhaps we got to wait for a VB cleanup volunteer to come in.

hongjun
Good news to all of those experts paticipated here:)

Questioner came back and is asking same question again.

https://www.experts-exchange.com/questions/20728585/the-previous-question-'-there-are-a-z-alphabets'.html
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split hongjun 150 Grade A, JoelSoft 50 Grade A, srimanth 50 Grade A

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

leonstryker
EE Cleanup Volunteer