Advertisement
andrefecto

Convert word to pig latin

Nov 21st, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class frmMain
  2.     'Name: Pig Latin
  3.    'Purpose: Convert words to pig latin
  4.    'Andre Fecteau - 11/8/15 - 11/11/15
  5.  
  6.     'Exit program button
  7.    Private Sub bttnExit_Click(sender As Object, e As EventArgs) Handles bttnExit.Click
  8.         Me.Close()
  9.     End Sub
  10.  
  11.     'what happens when someone clicks convert
  12.    Private Sub bttnConvert_Click(sender As Object, e As EventArgs) Handles bttnConvert.Click
  13.  
  14.         'Variable to save the original word in
  15.        Dim strOriginalWord As String
  16.  
  17.         'Set the variable = to what is in the text box
  18.        strOriginalWord = txtWord.Text
  19.  
  20.         'Quickly test if the first letter is a vowel
  21.        If strOriginalWord.Substring(0, 1).ToUpper Like "[AEIOUY]" Then
  22.  
  23.             'if it is just add -way to the end and then finish
  24.            txtPigLatin.Text = addWay(strOriginalWord).ToString
  25.  
  26.             'if the first letter isn't a vowel then test if there is any vowel and if there is then do the following....
  27.        ElseIf testForVowel(strOriginalWord) = True Then
  28.  
  29.             'add the needed - to the end of the word
  30.            strOriginalWord = strOriginalWord + "-"
  31.  
  32.             'set the PigLatin box = to what the moveLettersToEnd outputs
  33.            txtPigLatin.Text = moveLettersToEnd(strOriginalWord).ToString
  34.  
  35.             'if the first letter isn't a vowel then test if there is any vowel and if there isn't do the following....
  36.        ElseIf testForVowel(strOriginalWord) = False Then
  37.  
  38.             'add -way to the end of the word then finish
  39.            txtPigLatin.Text = addWay(strOriginalWord).ToString
  40.  
  41.         End If
  42.     End Sub
  43.  
  44.     '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
  45.    Private Function moveLettersToEnd(ByVal strOriginalWord As String) As String
  46.  
  47.         'Will need a variable to save the first letter in
  48.        Dim charFirstLetter As Char
  49.  
  50.         ' using a do until loop to keep moving letters to the end until the first letter is AEIOU or Y
  51.        Do Until strOriginalWord.Substring(0, 1).ToUpper Like "[AEIOUY]"
  52.  
  53.             ' store the current first letter
  54.            charFirstLetter = strOriginalWord.Substring(0, 1)
  55.  
  56.             ' now insert the first letter to the end of the word
  57.            strOriginalWord = strOriginalWord.Insert(strOriginalWord.Length, charFirstLetter)
  58.  
  59.             ' now remove the first letter becuase it has already been added to the end
  60.            strOriginalWord = strOriginalWord.Remove(0, 1)
  61.  
  62.             ' 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
  63.            If strOriginalWord.Substring(0, 1).ToUpper Like "[AEIOUY]" Then strOriginalWord = strOriginalWord + "ay"
  64.         Loop
  65.  
  66.         'return the final version of the word
  67.        Return strOriginalWord
  68.     End Function
  69.     'made a repeatable function to add -way to the end when I need it
  70.    Private Function addWay(ByVal strOriginalWord As String) As String
  71.  
  72.         'return the concat string
  73.        Return strOriginalWord + "-way"
  74.     End Function
  75.  
  76.     'using this to see if the word has a vowel
  77.    Private Function testForVowel(ByVal strOriginalWord As String) As Boolean
  78.  
  79.         'create a boolean value to store true / false for it has a vowel in it
  80.        Dim boolHasVowel As Boolean = False
  81.  
  82.         'loop through the string to see if there is any vowels
  83.        For i = 0 To strOriginalWord.Length - 1
  84.             If strOriginalWord.Substring(i, 1).ToUpper Like "[AEIOUY]" Then boolHasVowel = True
  85.         Next
  86.  
  87.         'return the state of the boolean for use in the bttnConvert sub
  88.        Return boolHasVowel
  89.     End Function
  90.  
  91. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement