Filter: What have i done wrong

i am making a program that requires a filter and i have  got this so far, bearing that in mind, it might be all wrong.
Any answer that will work will do me fine.

heres what i got so far:

dim filteredWords, fWord() as string

filteredWords = "word1;word2;word3"
fWord = split (filterWords, ";")
for 1 = 0 to UBound(fWord)
     if InStr(1, Msg, fWord(i)) then
         msgbox (instr(1, msg, fWord(i)))
         replace msg, fWord(i), "$$$$"
     end if
next i
m1zz0Asked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Works great....

Private Sub Form_Load()
    Dim msg As String
    Dim filteredWords, fWord() As String

    msg = "The cat tried to eat the hamster but the alligator ate them both!"
    Debug.Print msg
    filteredWords = "cat;hamster;alligator"
    fWord = Split(filteredWords, ";")
    For i = 0 To UBound(fWord)
        msg = Replace(msg, fWord(i), String(Len(fWord(i)), "$"))
    Next i
    Debug.Print msg
End Sub
0
 
sirbountyCommented:
What are you trying to accomplish?

Private Sub FilterIt()
Dim filteredWords, fWord() As String

filteredWords = "word1;word2;word3"
fWord = Split(filteredWords, ";")
For i = 0 To UBound(fWord)
     If InStr(1, msg, fWord(i)) Then
         MsgBox (InStr(1, msg, fWord(i)))
         Replace msg, fWord(i), "$$$$"
     End If
Next i
End Sub
0
 
m1zz0Author Commented:
i need to search through the variable 'msg' for any of the words in the filteredWords list
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
sirbountyCommented:
Okay - then the revised should do that...
0
 
m1zz0Author Commented:
its not replacing the word, i did 'word1' for example, it says it is there, but the final output does not change it to "$$$$".  Any ideas?
0
 
sirbountyCommented:
Well, this line:
MsgBox (InStr(1, msg, fWord(i)))

Will display a message box showing the position where msg occurs in the current array string...

To replace the text,
newStr=replace (msg,fword(1),"$$$$")
0
 
m1zz0Author Commented:
it keeps doing something wrong,
newStr=replace (msg,fword(1),"$$$$")
keeps returning nothing, blank, but its ment to replace
ment to replace with "$$$$"
0
 
m1zz0Author Commented:
by the way, thnx for helping sirbounty, i could work on this for hours and never get it
0
 
sirbountyCommented:
So, after newstr line, you place a
MSGBOX newStr
and it doesn't come up $$$$
?
0
 
m1zz0Author Commented:
heres a little extra for the work, works great man, works a charm, but for some reason the debug.print thing dosent work on my computer.

Thnx sirbounty
0
 
sirbountyCommented:
You need to have the immediate window open (Ctrl + G)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Didn't mean to swoop in and steal your thunder sirbounty.  =(

Idle_Mind
0
 
sirbountyCommented:
Yea yea - I'll get you back... I've got your IP logged...
:D LOL
Hey man - no problem seriously - you picked up on it when I was still going "huh?"
Now, I understand what he was trying to accomplish - I'm glad you came along when you did.  Thanx!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.