Android Question If - Then - Else Statement using Consonant or a vowel

Jimpin23

New Member
If - Then - Else statement that determines if a given letter is a consonant or a vowel.Write an If - Then - Else statement that determines if a given letter is a consonant or a vowel.

Is this right?


Sub Globals

Private editText1 As EditText

Private btn1 As Button

End Sub

Sub btn1_Click

If editText1= “a” Or editText1=”A” Or editText1=”e” Or editText1=”E” Or editText1=”I” Or editText1=”I” Or editText1=”o” Or editText1=”O” Or editText1=”u” Or editText1=”U” then

Msgbox(“Vowel”,”Result”) Else

Msgbox(“Consonant”,”Result”)

End If

End Sub
 

JohnC

Expert
Licensed User
Longtime User
(you should use the CODE tag when posting code)

I would do it using a select case:
B4X:
Sub btn1_Click
     If IsVowel(editText1.text) then
        MsgboxAsync(“Vowel”,”Result”)
     else
        MsgboxAsync(“Consonant”,”Result”)
    end if
End If

Sub IsVowel (Letter as string) as boolean
    Select Case Letter.ToLowerCase
        Case "a", "e", "i", "o", "u"
            Return True
        Case Else
            Return False
    End Select
End Sub
 
Last edited:
Upvote 0
Top