Solved

Filter: What have i done wrong

Posted on 2004-04-15
13
207 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:m1zz0
  • 6
  • 5
  • 2
13 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 10837833
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
 

Author Comment

by:m1zz0
ID: 10837846
i need to search through the variable 'msg' for any of the words in the filteredWords list
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10837855
Okay - then the revised should do that...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:m1zz0
ID: 10837879
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 10837912
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
 

Author Comment

by:m1zz0
ID: 10837967
it keeps doing something wrong,
newStr=replace (msg,fword(1),"$$$$")
keeps returning nothing, blank, but its ment to replace
ment to replace with "$$$$"
0
 

Author Comment

by:m1zz0
ID: 10837973
by the way, thnx for helping sirbounty, i could work on this for hours and never get it
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 200 total points
ID: 10838025
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 10838030
So, after newstr line, you place a
MSGBOX newStr
and it doesn't come up $$$$
?
0
 

Author Comment

by:m1zz0
ID: 10838047
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 10838054
You need to have the immediate window open (Ctrl + G)
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 10838386
Didn't mean to swoop in and steal your thunder sirbounty.  =(

Idle_Mind
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10838397
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question