By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,327 Members | 2,627 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,327 IT Pros & Developers. It's quick & easy.

can anyone give me help on my pig latin converter?

P: 1
I am making a program for a pig latin converter.I have to use a function. if the word begins with a vowel add -way at the end if it does not begin with a vowel then add a dash to the end of the word until the first letter in the word is aeiouy then add ay to the end like chair would be air-chay. as of now all of my words are ending in way when I push my convert button


Expand|Select|Wrap|Line Numbers
  1.  Private Sub btnConvert_Click(sender As Object, e As EventArgs) Handles btnConvert.Click
  2.         ' declare the variables
  3.         Dim strWord As String
  4.  
  5.         'trim the input
  6.         strWord = txtWordenter.Text.Trim
  7.  
  8.         If strWord = "" Then
  9.  
  10.             MessageBox.Show("Please Enter a Word")
  11.  
  12.         End If
  13.  
  14.  
  15.  
  16.         If strWord <> Nothing Then
  17.  
  18.         End If
  19.  
  20.  
  21.         ' if input begins with a vowel
  22.         If strWord.ToString Like "[aeiou]*" Then
  23.             Call Convert_To_Pig(strWord)
  24.  
  25.         Else
  26.             ' if input begins with nonvowel
  27.             Call insertAy(strWord)
  28.         End If
  29.  
  30.         ' send focus to input
  31.         txtWordenter.SelectAll()
  32.  
  33.     End Sub
  34.  
  35.     Private Sub Convert_To_Pig(ByVal convertWord As String)
  36.         'function will put -way to words that  have vowels
  37.         Const Vowel As String = "-way"
  38.         txtConvertedword.Text = convertWord & Vowel
  39.  
  40.  
  41.     End Sub
  42.  
  43.     Private Sub insertAy(ByRef word As String)
  44.         ' sees if word contains nonvowels
  45.         Dim remainder As String = ""
  46.         Do Until word = ""
  47.             remainder += word(0)
  48.             word = word.Remove(0, 1)
  49.  
  50.             'if nonvowel is found
  51.             If word.ToLower Like "[aeiouy]* " Then
  52.                 txtConvertedword.Text = remainder & "-" & remainder & "-ay"
  53.                 Exit Sub
  54.  
  55.             End If
  56.         Loop
  57.         Call Convert_To_Pig(remainder)
  58.     End Sub
Apr 4 '15 #1
Share this Question
Share on Google+
1 Reply


Seth Schrock
Expert 2.5K+
P: 2,939
You don't say what is going wrong. However, there were a few things that I noticed in your code that could have been giving you problems so I have fixed those in the code below.
Expand|Select|Wrap|Line Numbers
  1.  Private Sub btnConvert_Click(sender As Object, e As EventArgs) Handles btnConvert.Click
  2.     ' declare the variables
  3.     Dim strWord As String
  4.  
  5.     'trim the input
  6.     strWord = txtWordenter.Text.Trim
  7.  
  8.     If strWord = "" Then
  9.  
  10.         MessageBox.Show("Please Enter a Word")
  11.  
  12.     Else
  13.         ' if input begins with a vowel
  14.         Select Case strWord.SubString(0, 1).ToUpper
  15.             Case "A", "E", "I", "O", "U"
  16.                 Call Convert_To_Pig(strWord)
  17.  
  18.             Else 'Nonvowel
  19.                 Call insertAy(strWord)
  20.         End If
  21.  
  22.         ' send focus to input
  23.         txtWordenter.SelectAll()
  24.  
  25.     End If
  26.  
  27.  
  28. End Sub
Jun 5 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.