Skip to main content

How to pass Array as a parameter to the function?

I stored field names in a array and tried to pass array as a parameter to a function but Idea threw an error.
sub main
      Dim fieldname(2) as String
      fieldname(0) = "Acct_num"
      fieldname(1) = "Acct_Desc"
      fieldname(2) = "JE_num"
       PrintArray(fieldname)
end sub
Function  PrintArray(Arrayname() as String) 
     for i = 0 to ubound(Arrayname)
           msgbox Arrayname(i)
     next
End Function
Any one got a solution?

Brian Element Sat, 07/18/2015 - 17:51
Hi Srihaliostar, You are missing the call for the PrintArray() function
Sub main
      Dim fieldname(2) As String
      fieldname(0) = "Acct_num"
      fieldname(1) = "Acct_Desc"
      fieldname(2) = "JE_num"
      Call PrintArray(fieldname)
End Sub
Function  PrintArray(Arrayname() As String) 
     For i = 0 To UBound(Arrayname)
           MsgBox Arrayname(i)
     Next
End Function