1
votes

I'm Getting "Object variable not set" at the end of Do While Loop. When I debug the agent, the pointer points at "loop" after the condition was met. The condition is that if the document is equal to 10 documents (less than 11), it must proceed. Can you help me? Below is the code:

Const NotesMacro$ = {@DBColumn("":"";@dbname;"Top10DCV";2)}
    retval = Evaluate(NotesMacro$)
    For t = 0 To UBound(retval)
        Set vc = CSVview.GetAllEntriesByKey(retval(t), True)
        Set v2entry = vc.GetFirstEntry
        doccount1 = 0

    Do While doccount1 < 11 AND v2entry.isValid()

            ReDim Preserve tmpArray3(tmpcount3)
            ReDim Preserve tmpArray4(tmpcount4)
            ReDim Preserve tmpArray5(tmpcount5)
            ReDim Preserve tmpArray6(tmpcount6)
            ReDim Preserve tmpArray7(tmpcount7)
            ReDim Preserve tmpArray8(tmpcount8)
            ReDim Preserve tmpArray9(tmpcount9)
            ReDim Preserve tmpArray10(tmpcount10)
            ReDim Preserve tmpArray11(tmpcount11)
            ReDim Preserve tmpArray12(tmpcount12)
            ReDim Preserve tmpArray13(tmpcount13)
            ReDim Preserve tmpArray14(tmpcount14)
            ReDim Preserve tmpArray15(tmpcount15)
            ReDim Preserve tmpArray16(tmpcount16)
            ReDim Preserve tmpArray17(tmpcount17)
            ReDim Preserve tmpArray18(tmpcount18)
            ReDim Preserve tmpArray19(tmpcount19)
            ReDim Preserve tmpArray20(tmpcount20)
            ReDim Preserve tmpArray21(tmpcount21)
            ReDim Preserve tmpArray22(tmpcount22)
            ReDim Preserve tmpArray23(tmpcount23)
            ReDim Preserve tmpArray24(tmpcount24)

            tmpArray3(tmpcount3) = v2entry.ColumnValues(3)
            tmpArray4(tmpcount4) = v2entry.ColumnValues(4)
            tmpArray5(tmpcount5) = v2entry.ColumnValues(5)
            tmpArray6(tmpcount6) = v2entry.ColumnValues(6)
            tmpArray7(tmpcount7) = v2entry.ColumnValues(7)
            tmpArray8(tmpcount8) = v2entry.ColumnValues(8)
            tmpArray9(tmpcount9) = v2entry.ColumnValues(9)
            tmpArray10(tmpcount10) = v2entry.ColumnValues(10)
            tmpArray11(tmpcount11) = v2entry.ColumnValues(11)
            tmpArray12(tmpcount12) = v2entry.ColumnValues(12)
            tmpArray13(tmpcount13)= v2entry.ColumnValues(13)
            tmpArray14(tmpcount14)= v2entry.ColumnValues(14)
            tmpArray15(tmpcount15)= v2entry.ColumnValues(15)
            tmpArray16(tmpcount16)= v2entry.ColumnValues(16)
            tmpArray17(tmpcount17)= v2entry.ColumnValues(17)
            tmpArray18(tmpcount18)= v2entry.ColumnValues(18)
            tmpArray19(tmpcount19)= v2entry.ColumnValues(19)
            tmpArray20(tmpcount20)= v2entry.ColumnValues(20)
            tmpArray21(tmpcount21)= v2entry.ColumnValues(21)
            tmpArray22(tmpcount22)= v2entry.ColumnValues(22)
            tmpArray23(tmpcount23)= v2entry.ColumnValues(23)
            tmpArray24(tmpcount24)= v2entry.ColumnValues(24)

            doccount1 = doccount1 + 1

            tmpcount3=tmpcount3 + 1
            tmpcount4=tmpcount4 + 1
            tmpcount5=tmpcount5 + 1
            tmpcount6=tmpcount6 + 1
            tmpcount7=tmpcount7 + 1
            tmpcount8=tmpcount8 + 1
            tmpcount9=tmpcount9 + 1
            tmpcount10=tmpcount10 + 1
            tmpcount11=tmpcount11 + 1
            tmpcount12=tmpcount12 + 1
            tmpcount13=tmpcount13 + 1
            tmpcount14=tmpcount14 + 1
            tmpcount15=tmpcount15 + 1
            tmpcount16=tmpcount16 + 1
            tmpcount17=tmpcount17 + 1
            tmpcount18=tmpcount18 + 1
            tmpcount19=tmpcount19 + 1
            tmpcount20=tmpcount20 + 1
            tmpcount21=tmpcount21 + 1
            tmpcount22=tmpcount22 + 1
            tmpcount23=tmpcount23 + 1
            tmpcount24=tmpcount24 + 1

            Print #datafileNum%,(tmpArray3(0) & ";" & tmpArray4(0))
            Set v2entry = vc.GetNextEntry(v2entry)

        Loop
    Next
    Close datafileNum%
    Exit Sub
1

1 Answers

2
votes

Change your condition to

Do While doccount1 < 11 AND Not v2entry Is Nothing

v2entry.isValid() can only be used if v2entry is a ViewEntry. It fails when v2entry is Nothing. This is the case when Set v2entry = vc.GetNextEntry(v2entry) was executed for last entry.

You might use v2entry.isValid() though if a document can be deleted after your ViewEntryCollection was created. Your code would look like this then:

Do While doccount1 < 11 AND Not v2entry Is Nothing
    If v2entry.isValid() Then
        ...
    End If
Loop