Translating English to Pig Latin in VB


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: Translating English to Pig Latin in VB

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Translating English to Pig Latin in VB

    [Originally posted by Malarkey]

    Yeah how would i go about doing this.

    If the word begins with A, E, I, O, or U then add AY to the end of the word. (for example, APPLE becomes APPLEAY).

    Otherwise, the first letter of the word is put at the end of the word, and AY is added to the end (for example, SAND becomes ANDSAY)

    so Hey ***

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Translating English to Pig Latin in VB

    [Originally posted by Interloper]

    Okay...

    Dim strInput as String, str1stCharacter as String, strOutput as String, intStringLength as Integer
    strInput = txtInput.Text
    str1stCharacter = left(strInput, 1)
    If str1stCharacter = "A" or str1stCharacter = "E" or str1stCharacter = "I" or str1stCharacter = "O" or str1stCharacter = "U" then
    strOutput = strInput & "AY"
    Else
    intLen = len(strString1) - 1
    strOutput = right(strInput, intStringLength) & str1stCharacter & "AY"
    End If
    lblOutput.Caption = strOutput

    ...This could be in a click event for a button, assuming you have a text box and a label named txtInput and lblOutput, respectively. Hope this helps because I haven't done VB in a while. :)

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Use this one...

    [Originally posted by Interloper]

    Oops...

    Dim strInput as String, str1stCharacter as String, strOutput as String, intStringLength as Integer
    strInput = txtInput.Text
    str1stCharacter = left(strInput, 1)
    If str1stCharacter = "A" or str1stCharacter = "E" or str1stCharacter = "I" or str1stCharacter = "O" or str1stCharacter = "U" then
    strOutput = strInput & "AY"
    Else
    intStringLength = len(strInput) - 1
    strOutput = right(strInput, intStringLength) & str1stCharacter & "AY"
    End If
    lblOutput.Caption = strOutput

    ...Sorry about that, I named a few things wrong.

  4. #4
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Translating English to Pig Latin in VB

    [Originally posted by Chris Carta]

    This makes me think (which is dangerous)...
    What if you had the word HONOR? Since it is pronounced like it begins with an O but it begins with an H, you'ld need exception logic for it not to come out as onorHay.
    Chris

  5. #5
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Translating English to Pig Latin in VB

    [Originally posted by Interloper]

    Then you could put an elseif condition after the if like this...

    ElseIf left(strInput, 2) = "HO" then
    strOutput = right(strInput, intStringLength) & "AY"

    ...and then the else statement after this. Not too hard to fix. ;)


  6. #6
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re:Translating English to Pig Latin in VB

    [Originally posted by Chris Carta]

    The problem with this would be a word like HONOR and a word like HOME.

    Only one fits the exception. I don't mean to sound anal but I had an assignment like this once with a dialog box that had to use the word 'a' or 'an' depending on the beginning vowel of the next word. For example:

    AN Apple
    A Banana

    It seems petty, but I hadda say it.
    Chris

  7. #7
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re:Re:Translating English to Pig Latin in VB

    [Originally posted by Interloper]

    Fine...

    strHOChk = right(strInput, 1)

    ...this would go right before the If... ElseIf... Else... Condition...

    ElseIf left(strInput, 2) = "HO" and strHOChk <> "A" and strHOChk <> "E" and strHOChk <> "I" and strHOChk <> "O" and strHOChk <> "U" then
    strOutput = right(strInput, intStringLength) & "AY"

    ...this new ElseIf condition might actually work right. >8[

  8. #8
    Join Date
    Jan 2013
    Posts
    1

    Pig Latin Sentence

    I have an assignment where I need to translate a sentence not just a word, how would I do that?

  9. #9
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    By putting every word in the sentence through the logic loops described earlier.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center