Solved

How do I filter an array using the filter function?

Posted on 2004-09-23
10
653 Views
Last Modified: 2008-02-01
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!
0
Comment
Question by:majnun
10 Comments
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 167 total points
ID: 12134886
Dim testArray(2) As String

testArray(3) = "Goodbye" << Doesn't this give you an out of bounds error?
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 167 total points
ID: 12134905
Worked perfectly for me in VB6.  It returned "Hello" and "Goodbye".

Option Explicit

Private Sub Command1_Click()
    Dim i As Integer
    Dim testArray(2) As String
    Dim testArray2() As String
   
    testArray(0) = "Hello"
    testArray(1) = "Dude"
    testArray(2) = "Goodbye"
   
    testArray2 = Filter(testArray, "o")
    For i = LBound(testArray2) To UBound(testArray2)
        Debug.Print testArray2(i)
    Next i
End Sub
0
 
LVL 8

Assisted Solution

by:mladenovicz
mladenovicz earned 166 total points
ID: 12134916
        testArray(3) = "Goodbye"

should be

         testArray(2) = "Goodbye"
0
 

Author Comment

by:majnun
ID: 12136960
Woops ;)
0
 

Author Comment

by:majnun
ID: 12137030
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?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 32

Expert Comment

by:Erick37
ID: 12137158
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!
0
 

Author Comment

by:majnun
ID: 12137282
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!!!
0
 

Author Comment

by:majnun
ID: 12137291
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?
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12137464
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.
0
 

Author Comment

by:majnun
ID: 12137838
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.


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

939 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

Need Help in Real-Time?

Connect with top rated Experts

1 Experts available now in Live!

Get 1:1 Help Now