Hello guyz can anyone help me with counting vowels in a string and validating if the string only contain vowels using function in vb.net

You can activate a function by making a comparison .Just use a IF ELSE statement.If the string contains vowels then write code within the IF & END IF.
You can compare like this
If a="a" or a="e" or a="i" then
code
End If
You can count total length of a text.Make a For Loop set 0 to Text total length make a search to find total vowels.In Rich Text Box it is easy to find one word or letter.
Make one search and using if , if it is a vowel then add one to an integer like this
Dim b as integer
Dim a as String
If a="a" or a="e" or a="i" then
b=b+1
End If

Best Of Luck ....

You can activate a function by making a comparison .Just use a IF ELSE statement.If the string contains vowels then write code within the IF & END IF.
You can compare like this
If a="a" or a="e" or a="i" then
code
End If
You can count total length of a text.Make a For Loop set 0 to Text total length make a search to find total vowels.In Rich Text Box it is easy to find one word or letter.
Make one search and using if , if it is a vowel then add one to an integer like this
Dim b as integer
Dim a as String
If a="a" or a="e" or a="i" then
b=b+1
End If

Best Of Luck ....

Using the IndexOf method of an array that .Net provides will save you from having to write tons of If comparisons and is much faster in its execution.

Sub Main()
        Dim arrVowels() As String = {"a", "e", "i", "o", "u"}
        Dim strSearchText As String = "Programming"
        Dim intVowelCounter As Integer = 0

        For Each c As Char In strSearchText
            If Array.IndexOf(arrVowels, c.ToString.ToLower) >= 0 Then intVowelCounter += 1
        Next
        Console.WriteLine("Number of Vowels Found: {0}", intVowelCounter)

        If intVowelCounter = strSearchText.Length Then
            Console.WriteLine("All letters in the search text are vowels")
        End If
        Console.ReadLine()
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.