使用 NotesViewNavigator 在视图中的两个日期之间搜索文档

Search documents between two dates in a view with a NotesViewNavigator

我尝试获取所有创建日期在两个日期(开始和结束)之间的文档。

我有一个有时会出现日期的错误。如果最后一个类别是 15/01/2015,我将开始日期 or/and 结束日期设为 15/01/2015 :"object variable not set"。没看懂。

我的所有文档中都有一个视图。这是一个分类视图。 我想用 notesviewnavigator 浏览这个视图。

当我的文档的创建日期等于或介于开始日期或最终日期之间时,我将此文档放入我的 collection 最终日期。 在我的程序结束时,我将所有内容放在一个文件夹中并显示视图。

这是我的代码:

    Function RechercheDocParDate(dateDebut As String, dateFin As String, nomFolder1 As String, nomFolder2 As String, nomFolder3 As String, nomVue As String, numColonne As Integer) As Integer
' recherche les documents d'une vue en fonction de dates passées en paramètre pour les créer dans un folder privé

    Dim vueRech As NotesView    
    Dim j As Integer
    Dim collecEntryFinal As NotesViewEntryCollection
    Dim entry As NotesViewEntry
    Dim colonDate As String 
    Dim nbDocTrouve As Integer
    Dim flag As Boolean
    Dim nav As NotesViewNavigator
    Dim dbb As NotesDatabase    
    Dim Session As New NotesSession

    Set dbb = session.CurrentDatabase
    ' Récupération des données de la vue    
    Set vueRech = dbb.GetView(nomVue)   
    Call vueRech.Refresh    

    nbDocTrouve = 0

    ' a revoir : initialisation de la création d'entry
    ' création d'une collection d'entry (moins consommateur car le document n'est pas ouvert)   
    Set collecEntryFinal = vueRech.GetAllEntriesByKey("_gdfgdfg")   
    j = 1
    flag = True     

    ' création d'un navigateur de catégorie d'entry
    Set nav = vueRech.CreateViewNav
    Set entry = nav.GetFirst

'   si on n'est pas rendu à la fin de la vue (penser aux hors catégories)   
    While ( (Not (entry Is Nothing) ) And ( flag = True ) )  
'       si c'est bien une categorie
        If entry.IsCategory Then            
            'récupère la colonne de date 
            colonDate =  entry.ColumnValues(numColonne) 
            If ( colonDate >= dateDebut ) Then
                If  ( colonDate > dateFin ) Then                    
                    flag = False
                Else    
                    Set entry = nav.GetNext(entry)
                    's'il y a des documents
                    While ( (Not (entry Is Nothing) ) And (entry.IsDocument) )
                        'recupere les documents de la catégorie                     
                        Call collecEntryFinal.AddEntry(entry)                   
                        nbDocTrouve = nbDocTrouve + 1           
                        Set entry = nav.GetNext(entry) 
                        '//ALERT
                        ' it finds the documents but in the end of the list of document it crashes here
                        '//ALERT

                    Wend  
                    Set entry = nav.GetPrev(entry)      
                    End If              
                End If
            Else            
                'recupere les documents hors catégorie
                While ( (Not (entry Is Nothing) ) And (entry.IsDocument) )      
                    Call collecEntryFinal.AddEntry(entry)                   
                    nbDocTrouve = nbDocTrouve + 1       
                    Set entry = nav.GetNext(entry)      
                Wend    
            End If
            Set entry = nav.GetNextCategory(entry)  
        Wend    

        'on crée le dossier  privé pour l'utilisateur
        'si on trouve des résultats ils sont ajoutés dans le folder
        If Not Isempty(collecEntryFinal)  Then
            If nomFolder1 <> ""  Then               
                collecEntryFinal.PutAllInFolder(nomFolder1) 
            End If
            If nomFolder2 <> ""  Then       
                collecEntryFinal.PutAllInFolder(nomFolder2) 
            End If
            If nomFolder3 <> ""  Then           
                collecEntryFinal.PutAllInFolder(nomFolder3) 
            End If
        End If  
        Call vueRech.Refresh
        RechercheDocParDate = nbDocTrouve

    End Function

当我一步一步地做时,我理解它,但在最后(查看代码,我发出警报)

不确定您是否仍然遇到此问题,但为了将来参考,解决方案很简单。

您有一个嵌套的 while/wend 循环来循环浏览导航器每个类别中的文档。这个内部 while/wend 可以耗尽导航器中所有可用的文档,导致 "entry" 变成 "nothing"。然后,您在此嵌套 while 之外调用 nav.getPrev() 或 nav.GetNextCategory(),导致您的异常,因为无法使用未定义调用这两个 nav.getPrev() nav.GetNextCategory() , 或 "nothing", 参数.

The documentation concerning the "entry" parameter for GetNextCategory 明确指出 "If you specify Nothing, this method generates an error."

The documentation concerning the "entry" parameter for GetPrev 表示相同。

解决问题的代码:

Function RechercheDocParDate(dateDebut As String, dateFin As String, nomFolder1 As String, nomFolder2 As String, nomFolder3 As String, nomVue As String, numColonne As Integer) As Integer
    ' recherche les documents d'une vue en fonction de dates passées en paramètre pour les créer dans un folder privé

    Dim vueRech As NotesView    
    Dim j As Integer
    Dim collecEntryFinal As NotesViewEntryCollection
    Dim entry As NotesViewEntry
    Dim colonDate As String 
    Dim nbDocTrouve As Integer
    Dim flag As Boolean
    Dim nav As NotesViewNavigator
    Dim dbb As NotesDatabase    
    Dim Session As New NotesSession

    Set dbb = session.CurrentDatabase
    ' Récupération des données de la vue    
    Set vueRech = dbb.GetView(nomVue)   
    Call vueRech.Refresh    

    nbDocTrouve = 0

    ' a revoir : initialisation de la création d'entry
    ' création d'une collection d'entry (moins consommateur car le document n'est pas ouvert)   
    Set collecEntryFinal = vueRech.GetAllEntriesByKey("_gdfgdfg")   
    j = 1
    flag = True     

    ' création d'un navigateur de catégorie d'entry
    Set nav = vueRech.CreateViewNav
    Set entry = nav.GetFirst

    '   si on n'est pas rendu à la fin de la vue (penser aux hors catégories)   
    While ( (Not (entry Is Nothing) ) And ( flag = True ) )  
    '       si c'est bien une categorie
        If entry.IsCategory Then            
            'récupère la colonne de date 
            colonDate =  entry.ColumnValues(numColonne) 
            If ( colonDate >= dateDebut ) Then
                If  ( colonDate > dateFin ) Then                    
                    flag = False
                Else    
                    Set entry = nav.GetNext(entry)
                    's'il y a des documents
                    While ( (Not (entry Is Nothing) ) And (entry.IsDocument) )
                        'recupere les documents de la catégorie                     
                        Call collecEntryFinal.AddEntry(entry)                   
                        nbDocTrouve = nbDocTrouve + 1           
                        Set entry = nav.GetNext(entry) 
                    Wend
                    ' ---FIRST FIX HERE---
                    If (Not (entry Is Nothing) ) Then
                        Set entry = nav.GetPrev(entry)
                    End If
                End If              
            End If
        Else            
            'recupere les documents hors catégorie
            While ( (Not (entry Is Nothing) ) And (entry.IsDocument) )      
                Call collecEntryFinal.AddEntry(entry)                   
                nbDocTrouve = nbDocTrouve + 1       
                Set entry = nav.GetNext(entry)      
            Wend    
        End If
        ' ---SECOND FIX HERE---
        If (Not (entry Is Nothing) ) Then
            Set entry = nav.GetNextCategory(entry)  
        End If
    Wend    

    'on crée le dossier  privé pour l'utilisateur
    'si on trouve des résultats ils sont ajoutés dans le folder
    If Not Isempty(collecEntryFinal)  Then
        If nomFolder1 <> ""  Then               
            collecEntryFinal.PutAllInFolder(nomFolder1) 
        End If
        If nomFolder2 <> ""  Then       
            collecEntryFinal.PutAllInFolder(nomFolder2) 
        End If
        If nomFolder3 <> ""  Then           
            collecEntryFinal.PutAllInFolder(nomFolder3) 
        End If
    End If  
    Call vueRech.Refresh
    RechercheDocParDate = nbDocTrouve

End Function

请注意有两个更改,都是针对 Nothing 的简单测试。这应该可以解决您的问题或类似问题。请记住 none 的 Navigator 导航方法接受 Nothing,您以后应该能够避免类似的问题。