Solved

How do I filter an array using the filter function?

Posted on 2004-09-23
10
656 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: 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: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
 
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
String manipulation in Visual Basic 7 83
Run code from text file in vb 1 87
how to Classify of email (pdf attachments) 7 50
checkbox to hide entire section 10 60
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

756 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