Results 1 to 6 of 6

Thread: PDA PigLatin application

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    16

    PDA PigLatin application

    I want to make a PDA application that converts english to pig latin. this is what i have but I am getting errors. Can anyone help me?

    VB Code:
    1. Private Sub cmdEngToPigLatin_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEngToPigLatin.Click
    2.         Dim s As Object
    3.         Dim Strings_Renamed As Object
    4.  
    5.         Strings_Renamed = Split(txtInput.Text, " ")
    6.         For s = 0 To UBound(Strings_Renamed)
    7.             Strings_Renamed(s) = VB.Right(Strings_Renamed(s), Len(Strings_Renamed(s)) - 1) & VB.Left(Strings_Renamed(s), 1) & "ay"
    8.         Next
    9.  
    10.         MessageBox.Show(Replace(Join(Strings_Renamed, " "), vbCrLf, ""), "Pig Latin")
    11.         txtInput.Text = ""
    12.         txtInput.Focus()
    13.     End Sub

  2. #2
    Fanatic Member -TPM-'s Avatar
    Join Date
    Jul 2005
    Posts
    850

    Re: PDA PigLatin application

    You should probably use a string array instead of an object.
    VB Code:
    1. Dim Strings_Renamed() As String
    I'd dim a string output and add each updated word to it, then you wouldn't need to worry about joining the array.

    What errors are you getting and on which line?
    TPM

    Add yourself to the VBForums Frappr Map!!

  3. #3
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: PDA PigLatin application

    this is my opinion but you should also think about starting to get away from old VB ways.

    look at the following...

    VB Code:
    1. Dim Strings_Renamed As String()
    2.  
    3.         Strings_Renamed = Me.txtInput.Text.Split(" "c) ' Split(txtInput.Text, " ")
    4.         For i As Integer = 0 To Strings_Renamed.Length - 1
    5.             Strings_Renamed(i) = Microsoft.VisualBasic.Right(Strings_Renamed(i), Strings_Renamed(i).Length - 1) + _
    6.                 Microsoft.VisualBasic.Left(Strings_Renamed(i), 1) + "ay"
    7.             'microsoft.VisualBasic.Right(
    8.             'Strings_Renamed(s) = VB.Right(Strings_Renamed(s), Len(Strings_Renamed(s)) - 1) & _
    9.             '    VB.Left(Strings_Renamed(s), 1) & "ay"
    10.         Next
    11.  
    12.         MessageBox.Show(String.Join(" "c, Strings_Renamed).Replace(vbCrLf, ""), "Pig Latin")
    13.         'MessageBox.Show(Replace(Join(Strings_Renamed, " "), vbCrLf, ""), "Pig Latin")
    14.         txtInput.Text = ""
    15.         txtInput.Focus()

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    16

    Re: PDA PigLatin application

    Thank you for your help.

  5. #5
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: PDA PigLatin application

    I love pig Latin, so I decided to add a few things to your idea.

    One, I think it's best to compartmentize the logic. Have one function to perform it on a single word, and another to do it to a string. Also, Pig lation doesn't take just the first letter, it's everything before the first vowel (for example "There" = "erethay".

    VB Code:
    1. Private Function ConvertStringToPig(ByVal str As String) As String
    2.         Dim strarray As String() = str.Split(" ")
    3.         If strarray.Length < 2 Then Return Eng2Pig(str) 'Handles one word strings.
    4.         Dim workstring As String = ""
    5.         For Each strvar As String In strarray
    6.             workstring += Eng2Pig(strvar) + " "
    7.         Next
    8.         workstring = workstring.Substring(0, workstring.Length - 1) 'Kill the last space.
    9.         Return (workstring)
    10.     End Function
    11.     Private Function Eng2Pig(ByVal str As String) As String
    12.         Dim Vowels As String = "aeiouAEIOUyY"
    13.         Dim positionToSplit As Integer = str.IndexOfAny(Vowels)
    14.         If positionToSplit <> -1 Then 'YOu split on the first vowel, not always the second char.
    15.             Return (str.Substring(positionToSplit) + str.Substring(0, positionToSplit) + "ay")
    16.         Else : Return str
    17.         End If
    18.     End Function

    Of course, this still doesn't fix the problem with capital letters, but that should be easy enough to fix..

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  6. #6
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: PDA PigLatin application

    I tweaked him a little too
    VB Code:
    1. 'Option Strict On
    2.     Private Function ConvertStringToPig(ByVal str As String) As String
    3.         Dim strarray As String() = str.Split(" "c)
    4.         If strarray.Length < 2 Then Return Eng2Pig(str) 'Handles one word strings.
    5.         Dim workstring As String = ""
    6.         For Each strvar As String In strarray
    7.             workstring += Eng2Pig(strvar) + " "
    8.         Next
    9.         Return (workstring.TrimEnd) 'Kill the last space.
    10.     End Function
    11.     Private Function Eng2Pig(ByVal str As String) As String
    12.         Dim Vowels() As Char = "aeiouAEIOUyY".ToCharArray
    13.         Dim SpecialChars() As Char = ("`1234567890-=~!@#$%^&*()_+<>?,./;[]\|}{:""").ToCharArray
    14.         'Handle Punctuation and special characters
    15.         Dim Excludestring As String
    16.         Dim positionToSplit As Integer = str.IndexOfAny(SpecialChars)
    17.         If str.IndexOfAny(SpecialChars) >= 0 Then
    18.             Excludestring = str.Substring(positionToSplit)
    19.             str = str.Substring(0, positionToSplit)
    20.         End If
    21.         positionToSplit = str.IndexOfAny(Vowels)
    22.         If positionToSplit <> -1 Then 'YOu split on the first vowel, not always the second char.
    23.             str = (str.Substring(positionToSplit, 1).ToUpper + str.Substring(positionToSplit + 1) + str.Substring(0, positionToSplit).ToLower + "ay")
    24.         End If
    25.  
    26.         Return str & Excludestring
    27.     End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width