Page 1 sur 1

[LS] - Initialiser une collection

MessagePublié: 24 Mars 2005 à 08:53
par oguruma
la classe NotesDocumentCollection possède une méthode addDocument permettant d'ajouter des documents dans une collection ; or comment faire pour alimenter une collection en partant de ZERO ? La classe NotesDocumentCollection ne possèdant pas de constructeur...

l'idée est donc d'initialiser une collection travers une méthode qui renvoie une collection de taille 0

Dim s As New NotesSession
Dim db As NotesDataBase
on error goto handleError
Set db = s.CurrentDatabase
Set collection=db.alldocuments.getfirstdocument().responses

si votre application ne gère pas de documents réponses...

MessagePublié: 12 Sep 2007 à 11:07
par Michael DELIQUE
une autre version

Code : Tout sélectionner
Function CollectionVide(wDB As NotesDatabase) As NotesDocumentCollection
   
   'Declaration Variables
   Dim Session As NotesSession
   Dim db As NotesDatabase
   
   On Error Goto ErreurHandle
   
   Set Session = New NotesSession
   Set DB = Session.Currentdatabase
   
   If  wDB Is Nothing Then
      If Not db.alldocuments.getfirstdocument() Is Nothing Then
         Set CollectionVide = db.alldocuments.getfirstdocument().responses
      End If
   Else
      If Not wDB.alldocuments.getfirstdocument() Is Nothing Then
         Set CollectionVide = wDB.alldocuments.getfirstdocument().responses
      End If
   End If
   
   If CollectionVide Is Nothing Then
      If wDB Is Nothing Then
         Set CollectionVide = db.Views(0).GetAllDocumentsByKey("New Collection Empty",True)
      Else
         Set CollectionVide = wDB.Views(0).GetAllDocumentsByKey("New Collection Empty",True)
      End If
   End If
   
   If Not CollectionVide Is Nothing Then
      If   CollectionVide.Count > 0 Then
         CollectionVide.RemoveAll(True)
      End If
   End If
   
   Exit Function
ErreurHandle:
   Msgbox "("+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
   Exit Function
End Function

MessagePublié: 04 Juin 2010 à 10:45
par Michael DELIQUE
depuis la R8, il ya un constructeur qui permet de créer une collection vide :

CreateDocumentCollection()