Function PigLatin (ByVal InputString As String) As String
    ' Copyright 1993 Stephen Schmidt
    ' All Rights Reserved
    '
    ' USERS OF THIS PROGRAM MUST ACCEPT THIS DISCLAIMER OF WARRANTY:  "THIS PROGRAM
    ' IS SUPPLIED AS IS.  THE AUTHOR DISCLAIMS ALL WARRANTIES, EXPRESSED OR
    ' IMPLIED, INCLUDING, WITHOUT LIMITATION, THE WARRANTIES OF MERCHANTABILITY AND
    ' OF FITNESS FOR ANY PURPOSE.  THE AUTHOR ASSUMES NO LIABILITY FOR DAMAGES,
    ' DIRECT OR CONSEQUENTIAL, WHICH MAY RESULT FROM THE USE OF THIS PROGRAM."
    '
    ' Copyrighted freeware--you can do anything you want this module except remove
    ' the disclaimer or any of the copyright notices.  Thanks for your cooperation.
    '
    ' Stephen Schmidt, CompuServe user 73200,3207.
    '
    ' CompuServe users:  Send any inquiries via CompuServe Mail to 73200,3207
    ' Internet users:  Send any inquiries via mail to 73200.3207@compuserve.com



    ' Converts a phrase from English into Pig Latin.
    ' Examples:
    '    ? PigLatin("go away")
    '    oga wayaa
    '
    ' Areas for future possible improvement:
    ' The handling of punctuation is not too good.  Also, it doesn't work too well
    ' with sentences that are properly capitalized.

    Dim Result As String
    Result = ""

    Dim XPoseChar As String * 1

    ' Track the current state--either "within whitespace" or "within a word"
    Dim InSpace As Integer
    InSpace = True

    ' Parse each character within the phrase.
    Dim CurChar As Integer
    For CurChar = 1 To Len(InputString)
        If Asc(Mid$(InputString, CurChar, 1)) <= 32 Then
            ' Current character is a space or a control character.
            If InSpace Then
                ' Already within whitespace; continue to echo whitespace characters.
                Result = Result + Mid$(InputString, CurChar, 1)
            Else
                ' Add suffix to the current word; switch states.
                Result = Result + XPoseChar + "a" + Mid$(InputString, CurChar, 1)
                InSpace = True
            End If
        Else
            ' Current character NOT a space or control character.
            If InSpace Then
                ' Reached the beginning of a word:  Keep the first character for placement
                ' at the end of the word; switch states.
                XPoseChar = Mid$(InputString, CurChar, 1)
                InSpace = False
            Else
                ' Second or subsequent character of a word; echo the character.
                Result = Result + Mid$(InputString, CurChar, 1)
            End If
        End If
    Next CurChar

    ' In case there's a word at the end of the phrase, add the suffix.
    If Not InSpace Then
        Result = Result + XPoseChar + "a"
    End If

    PigLatin = Result
End Function

