Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Fixing Up a Pig Latin Program!


Reply
 
Thread Tools Display Modes
  #1  
Old 04-26-2012, 05:26 PM
EMetalmulishaH's Avatar
EMetalmulishaH EMetalmulishaH is offline
Freshman
 
Join Date: Mar 2012
Location: NO WHERE
Posts: 39
Default Fixing Up a Pig Latin Program!


Hey I found this program.

I am using Visual basic 2010 Express.

I wanted to know how to make it better.

For example:

1)Make it translate full sentences.
2)Make it so that you can have punctuation marks.
3)And with words such as Th and Qu make them
like The = hethay and quick = ickquay

Code:
Public Class Form1

    Private Sub ConvertPigLatin(ByVal wordConvert As String, ByRef pigLatinWord As String)

        If wordConvert.Substring(0, 1).ToUpper Like "[AEIOU]" Then
            pigLatinWord = wordConvert & "way"
        End If

        Dim strTemp As String = ""

        If wordConvert.Substring(0, 1).ToUpper Like "[!AEIOU]" Then
            Do While wordConvert <> ""
                strTemp = strTemp + wordConvert(0)
                wordConvert = wordConvert.Remove(0, 1)

                If wordConvert.ToUpper Like "[AEIOUY]*" Then
                    pigLatinWord = wordConvert & strTemp & "ay"
                    Exit Sub
                End If
            Loop
        End If

        If strTemp.ToUpper Like "*[!AEIOUY]*" Then
            pigLatinWord = strTemp & "way"
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strOriginalWord As String
        Dim strPigLatin As String

        strOriginalWord = TextBox1.Text

        Call ConvertPigLatin(strOriginalWord, strPigLatin)
        Label1.Text = strPigLatin
    End Sub
End Class
__________________
"When all else fails, read the manual."
Reply With Quote
  #2  
Old 04-26-2012, 05:51 PM
EMetalmulishaH's Avatar
EMetalmulishaH EMetalmulishaH is offline
Freshman
 
Join Date: Mar 2012
Location: NO WHERE
Posts: 39
Default

I just need help figuring out what steps I need to take.
__________________
"When all else fails, read the manual."
Reply With Quote
  #3  
Old 04-26-2012, 06:29 PM
PlausiblyDamp's Avatar
PlausiblyDamp PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 1,952
Default

To translate an entire sentence you could split the sentence into individual words and then call this function for each word in turn.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #4  
Old 04-26-2012, 06:58 PM
EMetalmulishaH's Avatar
EMetalmulishaH EMetalmulishaH is offline
Freshman
 
Join Date: Mar 2012
Location: NO WHERE
Posts: 39
Default Thank You.

Thank you so much.
__________________
"When all else fails, read the manual."
Reply With Quote
  #5  
Old 05-01-2012, 03:43 PM
EMetalmulishaH's Avatar
EMetalmulishaH EMetalmulishaH is offline
Freshman
 
Join Date: Mar 2012
Location: NO WHERE
Posts: 39
Default

I need help fixing it, the program still will not split the spaces!
Code:
Imports System.Text

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim userImput As String
        Dim PigLatin As String
        userImput = TextBox1.Text
        Call pigLatinConvert(userImput, PigLatin)
        Label1.Text = PigLatin

       

    End Sub


    Private Sub pigLatinConvert(ByVal wordConvert As String, ByRef pigLatinWord As String)

        If wordConvert.Substring(0, 1).ToUpper Like "[AEIOU]" Then
            pigLatinWord = wordConvert & "way"
        End If

        Dim word As String = ""
        If wordConvert.Substring(0, 1).ToUpper Like "[!AEIOU]" Then
            Do While wordConvert <> ""
                word = word + wordConvert(0)
                wordConvert = wordConvert.Remove(0, 1)
                If wordConvert.ToUpper Like "[AEIOUY]*" Then
                    pigLatinWord = wordConvert & word & "ay"
                    Exit Sub
                End If
            Loop
        End If
        If word.ToUpper Like "*[!AEIOUY]*" Then
            pigLatinWord = word & "way"
        End If

        Dim space As String()
        Dim output As New StringBuilder()
        Do While space Is wordConvert.Split(" ")

            For Each wordSpace In space
                output.Append(pigLatinWord)
                output.Append(" ")
            Next
        Loop

    End Sub
__________________
"When all else fails, read the manual."

Last edited by EMetalmulishaH; 05-01-2012 at 04:10 PM.
Reply With Quote
  #6  
Old 05-02-2012, 05:33 AM
DrPunk's Avatar
DrPunk DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

It looks like you're doing it the wrong way round. You want to work on the spaces before converting to piglatin.

Firstly, sort your Sub out. Returning values byref isn't great practice. A Function is far more suited to what you're trying to achieve.
Code:
Private Function PigLatin(byval word as string) as String
    dim pigLatinWord as String

    ' Do the work on word to convert it to pig latin in pigLatinWord

    ' Return the pig latin
    Return pigLatinWord
End Function
In your original example in the OP, the Button_Click would then become...
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = ConvertPigLatin(TextBox1.Text)
    End Sub
Much tidier.

OK, so with that function sorted, you could process a number of words divided by spaces by..
Code:
Dim build as String = "" ' A string to build the pig latin into
Dim words() as String 
dim s as string

' Split the text by space
words = Split(TextBox1.Text, " ")

' Work through each word, converting each word and appending it to the result
for each s in words
    build &= PigLatin(s) & " "
next

messagebox.show(build)
__________________
There are no computers in heaven!
Reply With Quote
  #7  
Old 05-02-2012, 02:02 PM
EMetalmulishaH's Avatar
EMetalmulishaH EMetalmulishaH is offline
Freshman
 
Join Date: Mar 2012
Location: NO WHERE
Posts: 39
Default Where do I put this?

Quote:
OK, so with that function sorted, you could process a number of words divided by spaces by..
Code:
Dim build as String = "" ' A string to build the pig latin into
Dim words() as String 
dim s as string
  
' Split the text by space
words = Split(TextBox1.Text, " ")

' Work through each word, converting each word and appending it to the result
for each s in words
    build &= PigLatin(s) & " "
next

messagebox.show(build)
__________________
"When all else fails, read the manual."
Reply With Quote
  #8  
Old 05-02-2012, 02:08 PM
EMetalmulishaH's Avatar
EMetalmulishaH EMetalmulishaH is offline
Freshman
 
Join Date: Mar 2012
Location: NO WHERE
Posts: 39
Default

THis is what I got so far.

Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim build As String = ""
        Dim words() As String
        Dim s As String
        words = Split(TextBox1.Text, " ")
        For Each s In words
            build &= pigLatinConvert(s) & " "
        Next
        MessageBox.Show(build)
        Label1.Text = pigLatinConvert(TextBox1.Text)

    End Sub

    Private Function pigLatinConvert(ByVal wordConvert As String)
        Dim pigLatinWord As String
        Dim word As String = ""
        If wordConvert.Substring(0, 1).ToUpper Like "[AEIOU]" Then
            pigLatinWord = wordConvert & "way"
        ElseIf wordConvert.Substring(0, 1).ToUpper Like "[!AEIOU]" Then
                Do While wordConvert <> ""
                    word = word + wordConvert(0)
                    wordConvert = wordConvert.Remove(0, 1)
                    If wordConvert.ToUpper Like "[AEIOUY]*" Then
                        pigLatinWord = wordConvert & word & "ay"
                    End If
                Loop
            End If
            Return pigLatinWord
    End Function
End Class
__________________
"When all else fails, read the manual."
Reply With Quote
  #9  
Old 05-02-2012, 02:28 PM
EMetalmulishaH's Avatar
EMetalmulishaH EMetalmulishaH is offline
Freshman
 
Join Date: Mar 2012
Location: NO WHERE
Posts: 39
Default

Never mind I got it right Thank you so much DrPunk, You are Awesome!!
__________________
"When all else fails, read the manual."
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->