Solved

Array in arguments of a sub

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Determine Range to Select 5 63
Can we place a tooltip on the actual vb6 form 5 56
RUNRMTCMD from AS/400 13 126
Fastest way to find and count same items VB6 16 62
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
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…

737 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