Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I filter an array using the filter function?

Posted on 2004-09-23
10
Medium Priority
?
663 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 668 total points
ID: 12134886
Dim testArray(2) As String

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

Accepted Solution

by:
Mike Tomlinson earned 668 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 664 total points
ID: 12134916
        testArray(3) = "Goodbye"

should be

         testArray(2) = "Goodbye"
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

824 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