Results 1 to 7 of 7
  1. #1
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662

    Split word in to vowels and consonants

    Think I'll have to use custom VBA function to do this.
    The Table
    myTable
    Field Names : WordTextID - PK; WordText - Unique
    Data
    Code:
    WordTextID   WordText    
    1  aardvark    
    2  abacterial 
    The Resultant Table to be generated based on Splitting the WordText based on continous Vowels or Continuous Consonants:
    Field Names : TheWordTextPartID - PK - Autonumber; WordTextID - FK; SerialNumber; TheWordTextPart




    TheWordTextPartID WordTextID SerialNumber TheWordTextPart
    1 1 1 aa
    2 1 2 rdv
    3 1 3 a
    4 1 4 rks
    5 2 1 a
    6 2 2 b
    7 2 3 a
    8 2 4 ct
    9 2 5 e
    10 2 6 r
    11 2 7 ia
    12 2 8 l



    The pseudo-code

    Code:
    select WordText from myTable
    
    rs
    
    
    while not rs.eof
    {
        TheWordText = rs(WordText)
        TheWordTextLength = LEN(TheWordText)
        j = 1
        for (i = 1 to TheWordTextLength)
        {
            TheWordTextPart = Mid(TheWordText,i,1)
            j = j
                
            if TheWordTextPart is Vowel 
                m = TheWordTextPart & TheWordTextPart
                insert in to Resultant table j,m
            else 
                n = TheWordTextPart & TheWordTextPart
                insert in to Resultant table j,n
            end if    
            
            j=j+1
        }
    
    
        rs.movenext
    loop
    }

    Facing problem where the consecutive alphabets are either vowels or consonants eg : how to manage in aardvark; aa & then rdv.


    Thanks
    Last edited by recyan; 03-11-2013 at 01:47 AM. Reason: Formatting & correcting Table Name ( No important changes from original content )

  2. #2
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    This sounds like a homework assignment. So, I'll help instead of just posting code.

    Basically, you want to keep the TheWordTextPart letters in a variable and only write them to the Table when they switch between vowels and non-vowels.

    For example, for each word, you'd want to do the following:
    1. When you first start a word, set up your variables: reset Segments to 1, and PreviousCharacter and TheWordTextPart to empty strings.
    2. For the first letter of each word, set PreviousCharacter to the first letter in the word (so your first comparison will always match)
    3. Then, for each letter in your word, compare it to PreviousCharacter
    4. If they're BOTH vowels or if NEITHER is a vowel,
      1. Tack the current letter to your TheWordTextPart variable
      2. Set PreviousCharacter to the current letter

    5. If they're not BOTH a Vowel and they're not BOTH a consonant,
      1. Write your TheWordTextPart to the database
      2. Increment Segments
      3. Set TheWordTextPart to JUST the current letter
      4. Set PreviousCharacter to the current letter

    6. Then move to the next letter in the word
    7. If you're on the last letter in the word,
      1. If TheWordTextPart has at least one character in it,
        1. Write your TheWordTextPart to the database


    8. Jump back to the top and start the next word

  3. #3
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Hi,
    Thanks for replying.
    It's not a homework assignment, though I would have loved to be back to my homework days.
    I'll take a look at what you have suggested & try to convert it to VBA, though at first glance, it appears that I might have to come back for help.

    Thanks

  4. #4
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Hi Rawb,
    Need your help with the coding. It's beyond me presently & also my VBA skills are pretty basic. I have understood the logic that you have given, however am unable to translate it in to VBA.
    I assure you, I have crossed the Home Work Stage long long time back.

    Thanks

  5. #5
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Well then,

    When I coded it, I split it into two Functions:

    IsVowel() - You pass in a single character and the function returns True if it's a vowel or false if it's not.
    Code:
    Public Function IsVowel(Character As String) As Boolean
      ' This function checks the passed argument to see if it is a vowel or not. If
      ' it is a vowel, the function returns True. If not (or if more than one
      ' character is passed), it returns False.
      ' Arguments:
      '   Character - a string containing the character to check. If more than a
      '   single character is passed, the function returns False.
    
      ' Make sure the passed argument is only a single character
      If Len(Character) = 1 Then
        ' Is the character a vowel
        If LCase(Character) = "a" Or LCase(Character) = "e" Or LCase(Character) = "i" Or LCase(Character) = "o" Or LCase(Character) = "u" Then
          ' If it is
          IsVowel = True ' Return True
        Else
          ' If it's not
          IsVowel = False ' Return False
        End If
      Else
        ' If it's more than one char
        IsVowel = False ' Return False
      End If
    End Function
    CustomSplit() - Reads a collection of words from the database and, using IsVowel(), splits them into groupings of consecutive vowels and consonants.
    Code:
    Public Sub CustomSplit()
      ' This function looks at the words listed in the input Table 'MyTable' and,
      ' one at a time, splits them into groupings of consecutive consonants and
      ' vowels. These groupings are then saved into the output Table 'Output'.
      ' Arguments:
      '   NONE
    
      ' Use DAO Recordsets to connect to a Table in the DB
      Dim db1 As DAO.Database
    
      Dim rstInput As DAO.Recordset
      Dim rstOutput As DAO.Recordset
    
      Dim i As Long
      Dim nbrSegment As Long
      Dim nbrWordLen As Long
      Dim strLastChar As String
      Dim strWordText As String
    
      Set db1 = CurrentDb()
    
      Set rstInput = db1.OpenRecordset("MyTable", dbOpenSnapshot) ' The input Table, read-only
      Set rstOutput = db1.OpenRecordset("Output", dbOpenDynaset) ' The output Table, writeable
    
      ' If the output Table has anything in it, empty it out. This will prevent
      ' duplicate entries if the function is run multiple times
      If Not rstOutput.RecordCount = 0 Then
        Do While Not rstOutput.EOF
          With rstOutput
            .Delete
          End With
    
          rstOutput.MoveNext
        Loop
      End If
    
      ' Are there any words saved into the input Table?
      If rstInput.RecordCount = 0 Then
        ' If not, alert the user
        MsgBox "No words to split!"
      Else
        ' If so, continue processing
    
        ' Loop through each word in the input Table and process them one at a time
        Do While Not rstInput.EOF
          ' When starting a (new) word, reset our variables
          nbrSegment = 1
          nbrWordLen = Len(rstInput("WordText")) ' Figure out how long the word is
          strLastChar = Mid(rstInput("WordText"), 1, 1) ' Set to the first letter of the word, forcint the first comparison to match
          strWordText = "" ' Make sure our string for the consecutive block of vowels or consonants is empty
    
          ' Perform the following comparison for each letter in the word
          For i = 1 To nbrWordLen Step 1
            ' Does the "vowel status" of the previous letter in the word match the
            ' "vowel status" of the current letter? Note: We don't care if the
            ' letters are vowels or not, only that they are either BOTH vowels or
            ' NEITHER OF THEM are vowels
            If IsVowel(strLastChar) = IsVowel(Mid(rstInput("WordText"), i, 1)) Then
              ' If they both have the same "vowel status"
              strLastChar = Mid(rstInput("WordText"), i, 1) ' Save the current letter so we can compare it against the next letter in the word
              strWordText = strWordText & strLastChar ' Add the current letter to our string of consecutive letters
            Else
              ' If the two letters don't match
    
              ' Write our current string of consecutive letters to the output Table
              With rstOutput
                .AddNew
                !WordTextID = rstInput("WordTextID")
                !SerialNumber = nbrSegment
                !TheWordTextPart = strWordText
                .Update
              End With
    
              ' Increment/Reset our variables
              nbrSegment = nbrSegment + 1 ' Increment our segment counter
              strLastChar = Mid(rstInput("WordText"), i, 1) ' Save the current letter for comparison
              strWordText = strLastChar ' Save the current letter to the string of consecutive letters (replacing the old string, not adding to the end)
            End If
          Next i
    
          ' If we're done with the word, write our current (last) set of
          ' consecutive letters to the output Table
          If Len(strWordText) > 0 Then
            With rstOutput
              .AddNew
              !WordTextID = rstInput("WordTextID")
              !SerialNumber = nbrSegment
              !TheWordTextPart = strWordText
              .Update
            End With
          End If
    
          ' Start on the next word
          rstInput.MoveNext
        Loop
      End If
    End Sub

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  7. #7
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Quote Originally Posted by Rawb View Post
    Well then,
    When I coded it, I split it into two Functions:
    ............
    Hi Rawb,
    Thanks a lot.
    Appreciate the effort.
    Will have a go & revert asap.
    Once again Thanks.

    Edit : Hi, I ran your code as it is, on a few sample data & it works great. Once again, Thanks a lot.

    Quote Originally Posted by orange View Post
    Recyan,

    Just curious--what is the application for this requirement?
    Hi Orange,

    I have a dyslexic left-handed kid ( me & others in my family are right-handed ) at home & I found myself at sea, when I sat down to teach him English language.
    What I am trying to do is, a rough analysis of the words occurring in English language, to familiarize myself with the language & then help him along.
    Rather, I should say, I'm educating myself to educate him.
    Edit :
    In fact, I had posted in another forum a slightly different requirement, some time back. Unfortunately, I did not get any response.
    Am posting the link, just in case, you or some one else could give me some pointers :

    http://forums.devshed.com/dev-shed-l...ds-934753.html

    Thanks
    Last edited by recyan; 03-13-2013 at 10:40 PM.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Call word object and import word fields
    By silverspr in forum Programming
    Replies: 3
    Last Post: 12-10-2012, 11:32 PM
  2. Access to Word - Multiple Word Templates?
    By alpinegroove in forum Programming
    Replies: 11
    Last Post: 06-12-2012, 04:42 PM
  3. Word in Access
    By Milo4ka in forum Access
    Replies: 0
    Last Post: 03-24-2011, 10:17 AM
  4. Split string when specific word is found
    By DB4284 in forum Programming
    Replies: 1
    Last Post: 11-18-2010, 03:30 PM
  5. access to word please help!
    By fiesta_rich in forum Import/Export Data
    Replies: 2
    Last Post: 04-14-2009, 09:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums