Solved

Array in arguments of a sub

Posted on 2004-08-23
4
298 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
[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
  • 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

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!

Question has a verified solution.

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

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…
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.
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 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…

717 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