PDA

View Full Version : How to pass a part of a Nested Array to a function?



prabhafriend
11-23-2010, 05:55 AM
fieldnames = Array(Array("Account Class", "LE", "Acc-Pro", "BU", "DS", "CCY", "Value"), Array("Account Class", "Legal Entity", "Account", "Business Unit", "Data Source", "CCY", "Balance (USD)"), , Array("Account Type", "Legal Entity", "Account", "Product", "Business Unit", "Data Source", "Transaction Currency", "USD Equiv - Prior Period"), Array(, , "+-", "=Right((), 6)", , "=Left((),3)"))

i=0
Call Locate_Matrix(files(i), fieldnames(i+1))

Function Locate_Matrix(ByVal bookname As String, fieldlist() As Variant) As Boolean

Why I am getting an Type mismatch saying "Array or User-defined type expected" Highlighting the fieldnames(i+1). At the same time Isarray(fieldnames(i+1)) returns true. How come?

Jan Karel Pieterse
11-23-2010, 07:28 AM
I think the signature of the function is wrong, change:

Function Locate_Matrix(ByVal bookname As String, fieldlist() As Variant) As Boolean


to:

Function Locate_Matrix(ByVal bookname As String, fieldlist As Variant) As Boolean

prabhafriend
11-23-2010, 07:47 AM
that means there is no need to explicitly declare variable as an array in functional parameters?

Jan Karel Pieterse
11-23-2010, 08:19 AM
No, it means that you can assign an array to a variable of type Variant, without declaring it as an array of variants.

prabhafriend
11-23-2010, 08:45 AM
Thank you Jan.