Solved

Array in arguments of a sub

Posted on 2004-08-23
4
290 Views
Last Modified: 2010-05-02
I have a sub which in the arguments list i want to pass the values of an array.
How do i do that?I don't want to write

Private Sub SomeThing(MyArray(1) as integer,MyArray(2) as integer....)

because i have to many values
0
Comment
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
Smallint earned 30 total points
ID: 11869674

Try

Private Sub SomeThing(MyArray() As Integer)

Cheers
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11869701
Just pass the whole array:

Private Sub SomeThing(MyArray() as integer,...)

    Dim i as Long
    For i = Lbound(MyArray) to Ubound(MyArray)
        'Do something with MyArray(i) eg....
        debug.print MyArray(i)
    Next i
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11869706
Use ParamArray

Public Sub test(ParamArray Params())
    Dim i As Integer
    For i = LBound(Params) To UBound(Params)
    Debug.Print Params(i)
    Next
End Sub

Private Sub Form_Load()
    Call test("a", "b", "c", "d")
End Sub
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11869719
Call it like this

Option Explicit

Private Sub Command1_Click()

    Dim d() As Integer
    ReDim d(1 To 10)
    Dim i As Integer
    For i = 1 To 10
        d(i) = i * 2
    Next i
    SomeThing d
End Sub

Private Sub SomeThing(MyArray() As Integer)

    Dim i As Long
    For i = LBound(MyArray) To UBound(MyArray)
        Debug.Print MyArray(i)
    Next i
   
End Sub
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

705 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