Solved

Filter: What have i done wrong

Posted on 2004-04-15
13
204 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

785 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