Array problem

Good morning, My problem is how to use array correct. I have a form with a “repeat” field, “repeat” field contains a text list, such as “15/12/2006”,“16/12/2006”,“17/12/2006”. I would like to create new documents based on the repeat field. in this case, I want to create 3 documents as the repeat field contains 3 list.

the code below does not work, I know there are some problems with the repeat field, but I don’t know how to fix it.

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim ndoc As NotesDocument



Set db = session.CurrentDatabase

Set doc = Source.document

If  Ubound(Source.Document.repeat(0))>1 Then

	For i=1 To Ubound(Source.Document.repeat(0))

		Set ndoc=db.CreateDocument

		ndoc.form="Reservation"

		ndoc.ReservedBy=doc.ReservedBy(0)

		ndoc.sDate=doc.repeate(i)

		ndoc.eDate=""

		ndoc.ResourceName=doc.ResourceName(0)

		ndoc.Description=doc.Description(0)

		Call ndoc.Save( False, True )

	Next

End If

the error message is “Type mismatch”.

Many thanks for help!

Linda

Subject: Array problem.

ndoc.sDate=doc.repeate(i)

This maybe an issue… you added an ‘e’ to repeat. This would cause your error as that field does not exist.

G.

Subject: Array problem.

is there a typo here?

ndoc.sDate=doc.repeate(i)

should it be

ndoc.sDate=doc.repeat(i)

Subject: RE: Array problem.

Thanks Nancy. I change the code to ndoc.sDate=CDat(doc.repeate(i))

but the problem is on this line:

if Ubound(Source.Document.repeat(0)>1 then

Any suggestions please!

Thanks,

Linda

Subject: Array problem.

this is your problem: If Ubound(Source.Document.repeat(0))>1 Then

For i=1 To Ubound(Source.Document.repeat(0))

You should be doing a forall over repeat.values:

Dim item As NotesItem

Set item = source.document.GetFirstItem( “repeat” )

Forall v In item.Values

Set ndoc=db.CreateDocument

ndoc.form=“Reservation”

ndoc.ReservedBy=doc.ReservedBy(0)

ndoc.sDate=v

ndoc.eDate=“”

ndoc.ResourceName=doc.ResourceName(0)

ndoc.Description=doc.Description(0)

Call ndoc.Save( False, True )

End Forall

Subject: RE: Array problem.

Thank you so much Peter. It works fine. That is what I want.

Once again. Thanks!! :slight_smile:

Linda

Subject: RE: Array problem.

BTW, your code before looks fine. The bug appears to be that you started your array reference at 1 instead of 0 (assuming the you don’t have Option Base 1 declared).

Anyhow, I think that the ForAll approach is superior, IMHO.