program-7

7. Write a program which will count all vowels, consonants, digits, special characters and blank spaces in a sentences (Using select case)


Sample Output of Our Program



Quit Program Screenshot



Program Listing

Const vowels = "aeiou"
Const consonants = "bcdfghjklmnpqrstvwxyz"

' This function will count the number of vowels in a given sentence
Private Function CountVowels(strText As String) As Integer
    Dim i As Integer
 Dim asciiToSearchFor As Integer
    For i = 1 To Len(LCase(strText))
        If InStr(1, vowels, Mid$(strText, i, 1), vbTextCompare) Then
            CountVowels = CountVowels + 1
         End If
    Next i
End Function

' This function will count the number of consonants in a given sentence
Private Function CountConsonants(strText As String) As Integer
    Dim i As Integer
 Dim asciiToSearchFor As Integer
    For i = 1 To Len(LCase(strText))
        If InStr(1, consonants, Mid$(strText, i, 1), vbTextCompare) Then
            CountConsonants = CountConsonants + 1
         End If
    Next i
End Function

Private Sub cmd_clear_Click()
txt_string.Text = " "
lbl_consonants.Caption = " "
lbl_vowels.Caption = " "
txt_string.SetFocus
End Sub

Private Sub cmd_count_Click()
no_vowels = CountVowels(txt_string.Text)
no_consonants = CountConsonants(txt_string.Text)
lbl_consonants.Caption = "The number of consonants in a sentence is  " & no_consonants & "."
lbl_vowels.Caption = "The number of vowels in a sentence is  " & no_vowels & "."
End Sub
'Quit Procedure
Private Sub cmd_quit_Click()
Dim Response As Integer
Response = MsgBox("Are You Sure You Want To Quit The Program", vbYesNo + vbQuestion, "Quit Program")
If Response = vbYes Then
End
Else
Me.Show
Me.txt_string.Text = ""
lbl_consonants.Caption = " "
lbl_vowels.Caption = " "
Me.txt_string.SetFocus
End If
End Sub