Array

Hi all, could you help me please,

I have an array as below:

n = 0	

While Not(doc Is Nothing)



If Isnull(Arraygetindex(Array1,key)) Then 

		Redim Preserve Array1(n)

		Array1(n) = key

		n = n + 1

	Else

		

		If (doc.SubmitDoc(0) = "N") Then '**there is a NameUser within this doc

			doc.SubmitDoc = "Y"

			Call doc.Save(True,True)

		End If			

	End If

End If

I have a log that has to show for each user that receive those documents as:

==> User1 received documents: 2 (2 documents marked as “Y” for this user)

==> User2 received documents: 1

==> User3 received documents: 5

How can I do this? Show the number for each user based on this array!

Thank´s for help,

Subject: RE: Array

It’s not completely clear what you’re trying to do.

I assume key contains the username retrieved from the document (though you don’t show that line). So your logic is, first, have we encountered this user before; if not, add them to the list, otherwise do some processing on the document. So you don’t want to process the first document you encounter for each user? That seems a little odd.

Since you need to keep track of two things – a list of usernames and an associated count for each user – you need a more complex data structure than an array, which can only store one thing – the names or the counts.

The easiest way to do this is with a List variable.

Dim usercounts List As Integer

If Iselement(usercounts(key)) Then

'already saw this user, so process the document

… (process document here)

usercounts(key) = usercounts(key) + 1

Else ’ new user, ignore the document but remember the name in case they have another.

usercounts(key) = 0

End If

Forall count In usercounts

if count > 0 then Print listtag(count) & " received " & count

End Forall

Subject: RE: Array

Thank´s for help. It almost work. Now, I don´t know why is showing as:

user1 received 2

user1 received 2

user2 received 1

user3 received 1

and there are 2 documents for User1. Each document this script is showing it.

Please, can you help me again? Thank you very much,

Subject: RE: Array

Use lists instead of arrays

Dim lstUsers as Integer

If Not IsElement(lstUser(“John Bigboote”)) Then

lstUser(“John Bigboote”) = 1

Else

lstUser(“John Bigboote”) = lstUser(“John Bigboote”) + 1

End If

Forall u in lstUser

Print “User name: " & ListTag(u) & " has " & u " & " documents”

End Forall

Subject: RE: Array

I can’t tell what you’re doing wrong without seeing the code, and unless you describe what you want it to be doing. See CRISPY link below.

  • Andre Guirard, IBM/Lotus Development

Useful blog: Best Practice Makes Perfect

For faster answers, be C R I S P Y

Subject: RE: Array

Hi Andre, I got it… Thank you very much for your assistance and great help.

Now, it´s working well. :slight_smile:

Subject: Array

Catherine,

Create a variable called count and every time your if statement finds a match, iterate it by 1:

count = count + 1

Then when you go to print, just add this count to your concatenated string like so:

Print user + "received documents: " + Cstr(count)

hth.

brandt

Subject: RE: Array

Thank´s for reply, but the problem is how can I show each user count?