I am making an english to pig latin translator and I cannot quite get this right! For some reason i can always get the first word to translate but the other words jumble together and sometimes repeat themselves.

The rules for this program are as follows: To translate an English word into a pig Latin word, place the first letter of the English word (if it is not a vowel) at the end of the English word and add the letters “ay.” If the first letter of the English word is a vowel, place it at the end of the word and add “y.” Using this method, the word “jump” become “umpjay,” the word “the” becomes “hetay” and the word “ace” becomes “ceay”. Blanks between words remain blanks.

So far this is what I've got:

Public Class Form1

    Private Sub btnTran_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTran.Click
        Dim Sentence As String, letter As String, wordI As String, word1 As String, word As Double, wordamount As Double, counter As Integer = 0, current As Double
        txtOutput.Text = ""
        Try
            Sentence = (txtInput.Text).ToUpper
            wordamount = Wordcount(Sentence)
            lbl1.Text = wordamount
            Do Until counter = wordamount
                Sentence = Sentence & " "
                If counter = 0 Then
                    word = Sentence.IndexOf(" ")
                    word1 = Sentence.Substring(0, word)
                Else
                    word = Sentence.IndexOf(" ", counter)
                    word1 = Sentence.Substring((txtOutput.Text.Length), word)
                End If
                letter = Microsoft.VisualBasic.Left(word1, 1)
                counter += 1
                If word1.Length > 1 Then
                    If letter = "A" Or letter = "E" Or letter = "I" Or letter = "O" Or letter = "U" Then
                        wordI = word1.Substring(1) & letter & "Y"
                        txtOutput.Text = txtOutput.Text & " " & wordI
                    ElseIf letter = "B" Or letter = "C" Or letter = "D" Or letter = "F" Or letter = "G" Or letter = "H" Or letter = "J" Or letter = "K" Or letter = "L" Or letter = "M" Or letter = "N" Or letter = "P" Or letter = "Q" Or letter = "R" Or letter = "S" Or letter = "T" Or letter = "V" Or letter = "W" Or letter = "X" Or letter = "Y" Or letter = "Z" Then
                        wordI = word1.Substring(1) & letter & "AY"
                        txtOutput.Text = txtOutput.Text & wordI
                    Else
                        MessageBox.Show("Please Use Letters", "Error")
                    End If
                Else
                    txtOutput.Text = txtOutput.Text & word1
                End If
            Loop
        Catch
            MessageBox.Show("Invalid Entry", "Error")
        End Try
    End Sub

    Function Wordcount(ByVal Sentence)
        Return System.Text.RegularExpressions.Regex.Matches(Sentence, "\w+").Count
    End Function

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtInput.Text = ""
        txtOutput.Text = ""
        lbl1.Text = ""
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class

That did help, thank you!

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.