Sunday, January 15, 2017

Consonants and Vowels in Visual Basic NET


Here is another simple program that I wrote using Visual Basic NET that will ask the user to give a string and then our program will count the number of consonants and vowels in the given string by our user. In this program I am using Microsoft Visual Studio Ultimate 2012 Edition. I hope you will find my work useful. Thank you.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing

Public Class Form1

    Const vowels = "aeiou"

    Const consonants = "bcdfghjklmnpqrstvwzyz"


    Private Function Count_All_Vowels(given_string As String) As Integer
        Dim i As Integer
        For i = 1 To Len(given_string)
            If InStr(1, vowels, Mid$(given_string, i, 1), vbTextCompare) Then
                Count_All_Vowels = Count_All_Vowels + 1
            End If
        Next i
        Return Count_All_Vowels
    End Function

    Private Function Count_All_Consonants(given_string As String) As Integer
        Dim i As Integer
        For i = 1 To Len(given_string)
            If InStr(1, consonants, Mid$(given_string, i, 1), vbTextCompare) Then
                Count_All_Consonants = Count_All_Consonants + 1
            End If
        Next i
        Return Count_All_Consonants
    End Function


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label2.Text = "The Number of Vowels is " & Count_All_Vowels(UCase(TextBox1.Text)) & "."
        Label3.Text = "The Number of Consonants is " & Count_All_Consonants(UCase(TextBox1.Text)) & "."
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        End
    End Sub
End Class




No comments:

Post a Comment