Results 1 to 7 of 7

Thread: *****---English to Pig Latin!!--*******

  1. #1

    Thread Starter
    Lively Member mykg4orce's Avatar
    Join Date
    Oct 2000
    Location
    CANADA
    Posts
    92

    Exclamation

    Hello i have saved all the words from a text field into an array called MyString(). This array has each words saved separatly, so if the text file says "Hello my name is" then the array saves "Hello" and "my" and "name" and "is" in itself. The problem is that I am trying to convert all the words in this array into PIG LATIN: here is what my code looks like:

    Make a new function

    Function EnglishToPig(EngWord As String) As String
    Dim strConvert As String
    strConvert = EngWord

    strConvert = Right(EngWord, Len(EngWord) - 1) & Left(EngWord, 1) & "ay"

    If Left(EngWord, 1) = UCase(Left(EngWord, 1)) Then
    strConvert = UCase(Left(strConvert, 1)) _
    & LCase(Right(strConvert, Len(strConvert) - 1))
    End If
    EnglishToPig = strConvert
    End Function

    '---------------------------------------------------------'

    Save words into an array:

    For i = 1 To Len(LineOfText)
    If Mid$(LineOfText, i, 1) <> " " Then
    ReDim Preserve MyString(Words)
    Do Until Mid$(LineOfText, i, 1) = " " _
    Or Mid$(LineOfText, i, 1) = "," Or Mid$(LineOfText, i, 1) = "." _
    Or Mid$(LineOfText, i, 1) = ":" Or Mid$(LineOfText, i, 1) = "-" _
    Or i > Len(LineOfText)
    MyString(Words) = MyString(Words) & Mid$(LineOfText, i, 1)
    i = i + 1
    Loop
    Words = Words + 1
    End If
    Next i

    '--------------------------------------------------------'

    this is how i am trying to output it into another text field but it gives me an error.

    '------------------------------------'
    ReDim Preserve MyString(0 To Words)
    Dim temp As String


    For i = 0 To Words
    temp = temp & EnglishToPig(MyString())
    Next i
    txtmain2.Text = temp
    '------------------------------------'

    PLEASE HELP!!!!!!!!!!

  2. #2
    Member
    Join Date
    Nov 2000
    Posts
    62
    What exactly does the error say?

  3. #3
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Howdy.
    Well, funny thing happened a few months ago, someone said it was difficult to write a functional Pig-Latin translator (here at work) and I took 15 minutes and threw this together. You'll need a textbox, a command button (Text1, Command1), and VB6 for this to work as is.
    Code:
    Private Sub Command1_Click()
        MsgBox PigConvert(Text1.Text)
    End Sub
    
    Private Function PigConvert(Message As String) As String
        Dim MSplit() As String
        Dim MConvert() As String
        Dim X As Long
        Dim Punctuation() As String
        
        If Message = "" Then
            PigConvert = "Please enter something in the textbox to convert!"
            Exit Function
        End If
        Message = Replace(Message, vbCrLf, " " & Chr(169) & " ")
        MSplit = Split(Message, " ")
        ReDim MConvert(UBound(MSplit))
        ReDim Punctuation(UBound(MSplit))
        
        For X = 0 To UBound(MSplit)
            If MSplit(X) <> Chr(169) Then
    NEXTCHECK:
                If MSplit(X) = "" Then GoTo NEXTX
                If NotLetter(Right(MSplit(X), 1)) = True And NotNumber(Right(MSplit(X), 1)) = True Then
                    Punctuation(X) = Right(MSplit(X), 1) & Punctuation(X)
                    MSplit(X) = Left(MSplit(X), Len(MSplit(X)) - 1)
                    'MsgBox Punctuation(X)
                    'MsgBox MSplit(X)
                    GoTo NEXTCHECK
                End If
            End If
    NEXTX:
        Next X
        
        For X = 0 To UBound(MSplit)
    RECHECK:
            If MSplit(X) <> "" Then
                If NotLetter(Left(MSplit(X), 1)) <> True Then
                    If IsVowel(Left(MSplit(X), 1)) = False Then
                        MConvert(X) = MConvert(X) & Mid(MSplit(X), 2) & _
                        "-" & Left(MSplit(X), 1) & "ay" & Punctuation(X)
                        Else
                        MConvert(X) = MConvert(X) & MSplit(X) & "-ay"
                    End If
                    Else
                    If Len(MSplit(X)) > 1 Then
                        MConvert(X) = MConvert(X) & Left(MSplit(X), 1)
                        MSplit(X) = Mid(MSplit(X), 2)
                        GoTo RECHECK
                        Else
                        MConvert(X) = MConvert(X) & MSplit(X)
                    End If
                End If
                Else
                MConvert(X) = Punctuation(X)
            End If
        Next X
        Message = Join(MConvert, " ")
        PigConvert = Replace(Message, " " & Chr(169) & " ", vbCrLf)
    End Function
    
    Private Function NotLetter(Message As String) As Boolean
        If Message <> "" Then
            If (Asc(Message) > 64 And Asc(Message) < 91) Or _
               (Asc(Message) > 96 And Asc(Message) < 123) Then
               NotLetter = False
               Else
               NotLetter = True
            End If
        End If
    End Function
    
    Private Function NotNumber(Message As String) As Boolean
        If Message <> "" Then
            If Asc(Message) > 47 And Asc(Message) < 58 Then
                NotNumber = False
                Else
                NotNumber = True
            End If
        End If
    End Function
    
    Private Function IsVowel(Message As String) As Boolean
        Select Case LCase(Message)
            Case "a"
                IsVowel = True
            Case "e"
                IsVowel = True
            Case "i"
                IsVowel = True
            Case "o"
                IsVowel = True
            Case "u"
                IsVowel = True
            Case Else
                IsVowel = False
        End Select
    End Function
    It fully compensates for whitespace, punctuation, and vowels. Type something in the textbox, hit the button, and a message box will pop up with the translation.

    Feel free to review this code and/or use it at your discretion, it is released as Public Domain.
    It isn't the most elegant way to do it, but it works well
    Have fun.
    -Excalibur

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Sorry guys, but what's Pig Latin?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Pig Latin is a constructed slang. Pretty much. You speak pig latin thusly:

    (English) Hello, Bob. Nix the tie.
    (P. Latin) ello-Hay, ob-Bay. ix-Nay, e-thay ie-tay.

    Just take the first consonant sound up to the first vowel sound and put it at the end of the word and tack on ay. This is how I learned anyway. The above program I wrote doesn't take into account consonant sounds, just the first consonant. If the first sound in the word is a vowel, you just tack ay to the end of the word. (ello-hay. ow-hay are-ay ou-yay?)

    Pretty quick and simple
    -Excalibur

  6. #6
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Hehe sounds pretty dumb
    (sorry for any people that feel offended)

    I-Ay Otta-Gay <? ow-Nay, ause-Cay his-Tay ounds-Say tupid-Say!

    hehe
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  7. #7
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    The next question has got to be WHY ??
    That's Mr Mullet to you, you mulletless wonder.

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