Link to home
Start Free TrialLog in
Avatar of majnun
majnun

asked on

How do I filter an array using the filter function?

I'm trying to use the filter function described here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/modcore/html/deconusingfilterfunctiontosearchstringarrays.asp

Here's a simple example:

         Dim testArray(2) As String
         Dim testArray2() As String
         testArray(0) = "Hello"
         testArray(1) = "Dude"
         testArray(3) = "Goodbye"
   
        testArray2 = filter(testArray, "o")

But I get this error:
"Wrong number of arguments, or invalid property assignment"

Thanks for the help!
SOLUTION
Avatar of Erick37
Erick37
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of majnun
majnun

ASKER

Woops ;)
Avatar of majnun

ASKER

Ok that was a problem, but i'm still getting the error...

hmmm....

shouldn't have awarded the points i guess, maybe yall can help me still...

i have a feeling maybe I need to add a reference to something (i'm working in an old access database)...

I'm using Access 2003, and when I type:
filter(...

it doesn't give me the helpful auto-complete help... perhaps i need a reference for this function or something?

Any ideas?
When in the VBA edit window, press F2.  This brings up the Object Browser.  Do a search for Filter on <all libraries>
I found it in the VBA library as VBA.Strings.Filter()

Hope it helps!
Avatar of majnun

ASKER

Thanks Erick37!

So this line works:

testArray2 = VBA.Strings.filter(testArray, "o")

My question, Why do I need to type VBA.Strings.filter... does that mean I'm using the wrong VBA reference or something?

I'm still a noob when it comes to how all the pieces fit together... I get the imports statement from VB .NET but I don't understand how all everything gets included into an Access VBA module.

Thanks!!!
Avatar of majnun

ASKER

I guess another way of phrasing the last question:

In Access 2003, how can I use the VBA.Strings.filter() function without having to type the "VBA.Strings." part?
I'm not sure why this is happening.

Try this:
In Tools->References make sure that Visual Basic For Applications is selected and at the top of the list.
Avatar of majnun

ASKER

Its is. But I notice a bunch of other non-selected Visual Basic for Applications at the bottom of the list.

The one that is checked at the top of the list is located in:
C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VB... something more can't see scrolls off form

Does does this look right? The other non-checked Visual Basic for Applications are dlls and what not in various system32 folders.