LotusScript: Frustrating Type Mismatch

I’m just getting back into serious Notes programming after a serious illness which caused brain damage. It’s interesting how spotty my “forgotten” is, but there are still things I’m re-learning after 5 years!

Here’s my problem:

I am trying to pass a multi-value Listbox field to a Sub, which in turn passes it on to another. This field contains an array of 1 to x form names which I need field names from. An array in the array is populated.

Here’s my code snippets:

Public Sub reSelectForms( d As NotesDocument )

’ this resets targetDbFieldNameCounter so that we can import the fields…

targetDbFieldNameCounter = 0

’ *********************************

’ The next line is where it bombs out with a Type Mismatch

Call getFieldNames( d.GetItem(“TargetDbForms” ).values )

doc.fieldNames = targetDbFieldNames

End Sub

…

’ I’ve tried an array as it is now, and List. Neither worked… :-<

Public Sub getFieldNames( formNames() As String )

Dim tForm As NotesForm

Forall forms In formNames

Set tForm = targetDb.GetForm( forms )

Forall field In tForm.Fields ’ now get the fields one at a time…

Redim Preserve targetDbFieldNames( targetDbFieldNameCounter ) ’ expand the size of the array

targetDbFieldNames( targetDbFieldNameCounter ) = field

targetDbFieldNameCounter = targetDbFieldNameCounter +1

End Forall

End Forall

End Sub

I guess what I’m trying to say is that I can’t use d.GetItem(“TargetDbForms” )(0), but that doesn’t even work!

Help! What am I missing?

Marcus

Subject: LotusScript: Frustrating Type Mismatch…

I would revise your code this way

Public Sub reSelectForms( d As NotesDocument )

Dim item as NotesItem 'TS added this line

targetDbFieldNameCounter = 0

Set item = d.GetFirstItem(“TargetDBForms”)

Call getFieldNames(item.Values)

'Call getFieldNames( d.GetItem(“TargetDbForms” ).values ) remove this line

doc.fieldNames = targetDbFieldNames

End Sub

…

’ I’ve tried an array as it is now, and List. Neither worked… :-<

Public Sub getFieldNames( formNames As Variant ) 'changed the parameter here

Dim tForm As NotesForm

Forall forms In formNames

Set tForm = targetDb.GetForm( forms )

Forall field In tForm.Fields ’ now get the fields one at a time…

Redim Preserve targetDbFieldNames( targetDbFieldNameCounter ) ’ expand the size of the array

targetDbFieldNames( targetDbFieldNameCounter ) = field

targetDbFieldNameCounter = targetDbFieldNameCounter +1

End Forall

End Forall

End Sub

Subject: Thanks. Now I get a “47:Type mismatch on Values” at compile time…

I really don’t understand…

Marcus

Subject: Thank you all… it was a scope issue…

Subject: LotusScript: Frustrating Type Mismatch…

Try this way using GetFirstItem instead of GetItem and a variant to store the multi values and pass the same variant:

Public Sub reSelectForms( d As NotesDocument )

dim frmlst as variant

…

frmlst = d.GetFirstItem(“TargetDbForms” ).values

Call getFieldNames(frmlst)

…

…

end sub

Public Sub getFieldNames(frmlst as variant )

…

end sub

Subject: LotusScript: Frustrating Type Mismatch…

By :Call getFieldNames( d.GetItem(“TargetDbForms” ).values )

I assume you mean

Call getFieldNames( d.GetFirstItem(“TargetDbForms” ).values )

which should return an array of strings IF the item contains only a list of strings…

Perhaps you should pass it as a variant?