Enhanced split function for text parsing

K

Kath

I found the subject entitled article on Microsoft Office 2000 Technical
Articles. I'm having trouble because I want the code to look at the table
that contains the memo field not the Private Sub SplitTest(). What code in
this article do I have to change to make this thing work? I don't want
message boxes I want them in a new table/field.

Kathy
 
K

Ken Snell [MVP]

Article URL or number? code example? Post some more details so that we know
of what you speak.
 
K

Ken Snell [MVP]

The SplitTest subroutine in that article is just a subroutine to show how
the article's Split function works. It would not be used in your code at
all, or at least I wouldn't expect it to be used.

Tell us what you want to accomplish in your code.... this article may or may
not be a way to do what you seek, but there also may be other ways to do
what you want. That will help us answer your original question.
 
K

Kath

Ok this is what I want to do....I want two text fields(memo) on a form. The
first text box would have an e-mail that is pasted from another program. The
other text box has a list of pasted "rules" (these are a listing of
unapproved words). The list of rules is pasted like this:

"bad " OR "bad word " OR "really bad word "

what I want to do is split the list up so each word or words is one record.
Then I want it to compare it against the first text box (the e-mail) and find
all the unapproved words from the list.

When I tried to use the split function, I would get the following:

"
bad
word
"
Or

exactly like the article says. But I having trouble with getting rid of the
SplitTest and using my own table....

If you have another solution or another approach, I'd love to hear it.

Thank you for your time!
Kathy
 
J

John Nurick

Hi Kath,

Does the list of "bad words" include bad phrases or just single words?
If it's only single words, or if it does include phrases but there's no
possibility that the word "or" will appear inside a "bad" phrase, you
can use the enhanced split function to split up your list of rules into
an array of words or phrases, something like this:

Dim arBadWords As Variant
Dim strRules As String

strRules = list of rules
arBadWords = EnhancedSplit(strRules, " OR ")


Similarly, if it's single words only, you can also use the enhanced
split function to split the email text into an array of words, ready to
loop through looking for bad words.

If you have to look for phrases, things get a bit more complicated.
 
K

Kath

John,

Ok, I tweaked your suggestion and I got what I wanted. I have the table with
the words in the field, the way I wanted it to work. I still need to search
the memo for the words that were created in the first piece and create some
kind of message box or form to show the results of the search. A suggestion
was made that I should open the recordset(words) and use the InStr function
to search the memo field in the other table. Can I do this? How do I do this?

Thanks!
Kathy
 
J

John Nurick

Hi Kath,
You could do something like this air code:

Dim rsBadWords As DAO.Recordset
Dim strBadWord As String
Dim strMessage As String
Dim strWordsFound As String

Set rsBadWords = CurrentDB.OpenRecordset blah blah

strMessage = Me.txtMemoField.Value 'get the text into the string

Do Until rsBadWords.EOF
strBadWord = rsBadWords.Fields(0).Value
If InStr(strMessage, strBadWord) > 0 Then
'Bad word found
strWordsFound = strBadWord & vbCrLf
End If
rsBadWords.MoveNext
Loop

But recordset operations are slow, and the multiple Instr() operations
would mean multiple sequential searches through the memo field. I
suspect it would be faster to use the enhanced Split function to (a)
split the list of rules into a variant array (let's call it arBadWords),
and (b) split the memo field into another variant array arMemoWords.

Then do something like this:

Dim i As Long
Dim j As Long
Dim strWordsFound As String

For i = 0 to UBound(arMemoWords)
For j = 0 to UBound(arBadWords)
If arBadWords(j) = arMemoWords(i) Then
strWordsFound = strBadWord & vbCrLf
End If
Next
Next
 
K

Kath

John,

I tried the code as suggested and I don't get the message box or an error.
Is the memo field too large? Could I use this:

Set db = CurrentDb()
Set rstWords = db.OpenRecordset("tblMyWords")
Set rstMemo = db.OpenRecordset("tblEmail")

Do Until rstWords.EOF
strWord = " " & rstWords!Words & " "
strMemo = rstMemo!ChkEmail

If strMemo.Find(strWord, lngSLine, lngSCol, lngELine, lngECol) = True Then
MsgBox "There is a bad word"
Else
MsgBox "This is a nice e-mail"
End If

I get an error saying that its missing the object.

Thanks!
Kathy
 
J

John Nurick

John,

I tried the code as suggested and I don't get the message box or an error.
Is the memo field too large? Could I use this:

There's no messagebox in the untested air code snippets I posted, so you
wouldn't get one unless you added a MsgBox statement yourself, e.g.

...
Next
Next
MsgBox strWordsFound, vbOKOnly, "Bad Words Found"


Set db = CurrentDb()
Set rstWords = db.OpenRecordset("tblMyWords")
Set rstMemo = db.OpenRecordset("tblEmail")

Do Until rstWords.EOF
strWord = " " & rstWords!Words & " "
strMemo = rstMemo!ChkEmail
What language are you writing code in? The next line doesn't make sense
in VBA, where there's no such thing as a string object with a fine
method.
 
K

Kath

?????

Kath said:
John,

I tried the code as suggested and I don't get the message box or an error.
Is the memo field too large? Could I use this:

Set db = CurrentDb()
Set rstWords = db.OpenRecordset("tblMyWords")
Set rstMemo = db.OpenRecordset("tblEmail")

Do Until rstWords.EOF
strWord = " " & rstWords!Words & " "
strMemo = rstMemo!ChkEmail

If strMemo.Find(strWord, lngSLine, lngSCol, lngELine, lngECol) = True Then
MsgBox "There is a bad word"
Else
MsgBox "This is a nice e-mail"
End If

I get an error saying that its missing the object.

Thanks!
Kathy
 
J

John Nurick

I replied to this last week but it must have gone astray. Here's what I
said:
John,

I tried the code as suggested and I don't get the message box or an error.
Is the memo field too large? Could I use this:

There's no messagebox in the untested air code snippets I posted, so you
wouldn't get one unless you added a MsgBox statement yourself, e.g.

...
Next
Next
MsgBox strWordsFound, vbOKOnly, "Bad Words Found"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top