Passing an array to a function

Hi all I am having difficulty passing an array to a function. Basically I need to loop through multiple items building an array.

Declarations

'Dim all the other stuff via scriptLibrary

Dim item As NotesItem

Dim whom() As String

Dim x As Integer

Dim q As Variant

sub sendEmail

Set ws = New notesUIWorkspace

Set uidoc = ws.currentDocument

Set s = New notesSession

Set db = s.currentDatabase

Set doc = uidoc.document

x = 0

Redim Preserve whom(x)

Set item = doc.GetFirstItem(“fieldName”)

Call myArray (q, item, whom, x) 'ERROR HERE

'ERROR ABOVE IS ‘Type mismatch on q’

'If I don’t pass q then I get the error

'more stuff

End Sub

Function myArray(item As NotesItem, whom() As String, x As Integer, q As Variant)

Forall q In item.Values 'ERROR HERE

'ERROR ABOVE IS ‘FORALL alias variable was previously declared: Q’

Redim Preserve whom(x)

whom(x) = q

x = x + 1

End Forall

End Function

Does this code make any sense? Thanks for the assistance!

Subject: passing an array to a function

You have defined q as a Variant (array) and your function “myArry” has defined it as a notesitem.

You should pass in the values to your Function in the order they are defined. Your first element you are passing in q but your function expects item.

Subject: Thanks - please check back tomorrow if you get a chance

I’m at home now and will try both your suggestions tomorrow but could definitely experience more problems. Thanks again. Tune in tomorrow EST.

Subject: Since your function is declared…

Function myArray(item As NotesItem, whom() As String, x As Integer, q As Variant)

Then I suggest you call it with

Call myArray(item, whom, x, q) 'SHOULD BE NO ERROR HERE

Subject: RE: Since your function is declared…

Thanks you Bill, matching the order in the calling sub proved successful.However I am still receiving the error in myArray function ‘FORALL alias variable previously declared: q’ and I’m not quite sure where to look. Thanks

Function myArray(item As NotesItem, whom() As String, x As Integer, q As Variant)

Forall q In item.Values

Redim Preserve whom(x)

whom(x) = q

x = x + 1

End Forall

End Function

Subject: You can not re-use q as a variable in your forall loop.

After looking at your function, I can not see why you are passing x and q as parameters at all. I also do not see why you have declared it as a Function and not a Sub.

Sub myArray(item As NotesItem, whom() As String)

x = Ubound(whom)

Forall q In item.Values

x = x + 1

Redim Preserve whom(x)

whom(x) = q

End Forall

End Sub

However in R6 there is a nice ArrayAppend function built in.

Whom = ArrayAppend(Whom, item.Values)

Subject: Thanks

Thanks Bill - that compiled.