Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class frmMain
- 'Name: Pig Latin
- 'Purpose: Convert words to pig latin
- 'Andre Fecteau - 11/8/15 - 11/11/15
- 'Exit program button
- Private Sub bttnExit_Click(sender As Object, e As EventArgs) Handles bttnExit.Click
- Me.Close()
- End Sub
- 'what happens when someone clicks convert
- Private Sub bttnConvert_Click(sender As Object, e As EventArgs) Handles bttnConvert.Click
- 'Variable to save the original word in
- Dim strOriginalWord As String
- 'Set the variable = to what is in the text box
- strOriginalWord = txtWord.Text
- 'Quickly test if the first letter is a vowel
- If strOriginalWord.Substring(0, 1).ToUpper Like "[AEIOUY]" Then
- 'if it is just add -way to the end and then finish
- txtPigLatin.Text = addWay(strOriginalWord).ToString
- 'if the first letter isn't a vowel then test if there is any vowel and if there is then do the following....
- ElseIf testForVowel(strOriginalWord) = True Then
- 'add the needed - to the end of the word
- strOriginalWord = strOriginalWord + "-"
- 'set the PigLatin box = to what the moveLettersToEnd outputs
- txtPigLatin.Text = moveLettersToEnd(strOriginalWord).ToString
- 'if the first letter isn't a vowel then test if there is any vowel and if there isn't do the following....
- ElseIf testForVowel(strOriginalWord) = False Then
- 'add -way to the end of the word then finish
- txtPigLatin.Text = addWay(strOriginalWord).ToString
- End If
- End Sub
- 'this function moves the first letter to the end then tests to see if the first letter is a vowel. If it is then it adds ay to the end of the word then finishes
- Private Function moveLettersToEnd(ByVal strOriginalWord As String) As String
- 'Will need a variable to save the first letter in
- Dim charFirstLetter As Char
- ' using a do until loop to keep moving letters to the end until the first letter is AEIOU or Y
- Do Until strOriginalWord.Substring(0, 1).ToUpper Like "[AEIOUY]"
- ' store the current first letter
- charFirstLetter = strOriginalWord.Substring(0, 1)
- ' now insert the first letter to the end of the word
- strOriginalWord = strOriginalWord.Insert(strOriginalWord.Length, charFirstLetter)
- ' now remove the first letter becuase it has already been added to the end
- strOriginalWord = strOriginalWord.Remove(0, 1)
- ' then if the first letter is now AEIOU or Y then added ay to the end of the word and the loop will close when it trys to loop again
- If strOriginalWord.Substring(0, 1).ToUpper Like "[AEIOUY]" Then strOriginalWord = strOriginalWord + "ay"
- Loop
- 'return the final version of the word
- Return strOriginalWord
- End Function
- 'made a repeatable function to add -way to the end when I need it
- Private Function addWay(ByVal strOriginalWord As String) As String
- 'return the concat string
- Return strOriginalWord + "-way"
- End Function
- 'using this to see if the word has a vowel
- Private Function testForVowel(ByVal strOriginalWord As String) As Boolean
- 'create a boolean value to store true / false for it has a vowel in it
- Dim boolHasVowel As Boolean = False
- 'loop through the string to see if there is any vowels
- For i = 0 To strOriginalWord.Length - 1
- If strOriginalWord.Substring(i, 1).ToUpper Like "[AEIOUY]" Then boolHasVowel = True
- Next
- 'return the state of the boolean for use in the bttnConvert sub
- Return boolHasVowel
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement