?
Solved

Array in arguments of a sub

Posted on 2004-08-23
4
Medium Priority
?
303 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 120 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
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…
Suggested Courses

777 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