# Count Vowels

Printable View

• 12-28-2007, 12:34 PM
RichardGR
Count Vowels
Ok, everyone get ready to laugh. :SICK:

I need to be able to count the number of vowels in a string, and display the count in a textbox. How would I do that?

(Please don't ask why :o )
• 12-28-2007, 12:46 PM
Hack
Quote:

Originally Posted by RichardGR
(Please don't ask why :o )

Ok, I won't (but, I really would like to know. :D )

Anyway, try something like this
Code:

```Private Function VowelCount(ByVal InputString As String) As Long Dim Vowel(11) As String Dim NumberOfVowels As Long Dim VowelFlag As Long Dim LengthOfString As Long Dim i As Long 'arrary of possible vowels Vowel(0) = "a" Vowel(1) = "i" Vowel(2) = "o" Vowel(3) = "u" Vowel(4) = "e" Vowel(5) = "y" Vowel(6) = "A" Vowel(7) = "I" Vowel(8) = "O" Vowel(9) = "U" Vowel(10) = "E" Vowel(11) = "Y" LengthOfString = Len(InputString)     For VowelFlag = 1 To LengthOfString         For i = 0 To 11             If Mid(InputString, VowelFlag, 1) = Vowel(i) Then                   NumberOfVowels = NumberOfVowels + 1             End If         Next     Next    VowelCount = NumberOfVowels MsgBox VowelCount End Function```
• 12-28-2007, 01:02 PM
Phil Weber
Here's another:
Code:

```Dim I As Integer Dim nVowels As Integer Dim Vowels As String Dim InputString As String Vowels = "aeiou" InputString = LCase(InputString) For I = 1 To Len(InputString)     If InStr(Vowels, Mid(InputString, I, 1)) Then         nVowels = nVowels + 1     End If Next MsgBox nVowels```
• 12-28-2007, 01:08 PM
Phil Weber
One more:
Code:

```Dim exp As RegExp Dim Matches As MatchCollection Dim nVowels As Integer Dim InputString As String Set exp = New RegExp With exp     .Pattern = "[aeiou]"     .Global = True     .IgnoreCase = True     Set Matches = .Execute(InputString) End With nVowels = Matches.Count```