Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Passing array through subs and functions.

Posted on 2002-03-18
4
Medium Priority
?
172 Views
Last Modified: 2010-05-02
Hi.

I have a dynamic array, and would like to pass it to a sub or function, how can I do so?
sub main()
dim array() as string

redim array(1 to 10)

call subroutine1(array)
end sub


public sub subroutine1(newarray() as string)

end sub

This doesnt work!


Thanks for helping me out.
0
Comment
Question by:samsonite1023
[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 70

Accepted Solution

by:
Éric Moreau earned 200 total points
ID: 6878908
Just like you started it (notice that I have changed your array variable name):

Private Sub Command1_Click()
Dim MyArray() As String
Dim i As Integer

    ReDim MyArray(1 To 10)
    For i = 1 To 10
        MyArray(i) = i
    Next i
   
    Call subroutine1(MyArray)
End Sub


Public Sub subroutine1(newarray() As String)
Dim i As Integer

    For i = LBound(newarray) To UBound(newarray)
        Debug.Print newarray(i)
    Next i
End Sub
0
 
LVL 18

Expert Comment

by:Crash2100
ID: 6878920
it should work fine the way it is, are you actually calling it array() in your program?  Because that's a reserved word, if you are try changing the name.
0
 
LVL 1

Author Comment

by:samsonite1023
ID: 6878939
Just a big mistake on my part!  I had it right on here, but in my actual code I left out the "Call" keyword.

So stupid!

Apparently without the "Call" keyword, it won't work.

Anyone know why?  I thought leaving Call out was perfectly fine.

Thanks

-Sam
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6878946
you may omit the Call but in this case, omit the parentheses too.
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 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…
Suggested Courses

596 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