Solved

Array in arguments of a sub

Posted on 2004-08-23
4
295 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

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