Solved

How do I filter an array using the filter function?

Posted on 2004-09-23
10
652 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

744 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

12 Experts available now in Live!

Get 1:1 Help Now