Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing array to a function

Status
Not open for further replies.

ecucurella

Programmer
Feb 17, 2003
34
ES
How can i pass an array to a funtion?

'call function
dim usr(10) as string
dim pwd(10) as string
dim bd(10) as string
dim server(10) as string
...
'assign values to arrays
usr(0)="pepe"
...
'calling function
if ObreBaseDades(Conn, 2,Usr(),Pwd(),Bd(),Server()) then
...

'Function declaration
Public Function ObreBaseDades(ByRef Conn As ADODB.Connection, ByVal numBD As Integer,Usr() As String, Pwd() As String, Bd() As String, Server() As String) As Boolean
...
end function


Thank you in advance :)
 
You can pass any array inside of a variant( leave off the brakets in the function declaration ).

Call it just like you show in your code:
If ObreBaseDades(Conn, 2,Usr(),Pwd(),Bd(),Server()) Then


Public Function ObreBaseDades(ByRef Conn As ADODB.Connection, ByVal numBD As Integer,Usr As Variant, Pwd As Variant, Bd As Variant, Server As Variant) As Boolean

And then read the variant as if it was the array.

Robert
 
ecucurella, are you getting any errors? I do it the way that you are doing it and it seems to work fine.

Code:
Dim myarray(3) As String

   myarray(0) = "This "
   myarray(1) = "is "
   myarray(2) = "a "
   myarray(3) = "test."
   TestSub myarray

Private Sub TestSub(pArray() As String)
   MsgBox pArray(0) & pArray(1) & pArray(2) & pArray(3)
End Sub


Take Care,

zemp

"Show me someone with both feet on the ground and I will show you someone who can't put their pants on."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top