Hi ,
Is there function or code so that i can open any document randomly from a Db. This needs for my Health Check activity of a db. Any help?
Hi ,
Is there function or code so that i can open any document randomly from a Db. This needs for my Health Check activity of a db. Any help?
Subject: Opening Document Randomly
You may use GetNthDocument(Index) method of Notesview class, if you have a view in the database, where no. of documents is changing frequently.
You can use @Random to get the value of Index.
HTH
Vinit
Subject: RE: Opening Document Randomly
I wrote a couple of functions to do that some time ago:
Parameters:lowerbound, upperbound and a boolean if you want to use a seed:
Function aleatorioEntero(rangoinferior As Integer, rangosuperior As Integer, semilla As Boolean) As Integer
Dim nro As Single
If semilla Then
Randomize
End If
nro=Cint(((rangosuperior-rangoinferior)*Rnd)+rangoinferior)
aleatorioEntero=Round(nro,0)
End Function
This other function to select “n”(numdocumentos) documents ramdomly from a notesdocumentcollection using the GetNthDocument method. This function returns a Notesdocumentcollection.
Function seleccionaleatoriapreguntas(numdocumentos As Integer, coleccion As NotesDocumentCollection) As NotesDocumentCollection
On Error Goto label
Dim ss As New NotesSession
Dim db As NotesDatabase
Dim i As Integer
Dim docseleccionado As Integer
Dim ndsel As NotesDocumentCollection
Dim usarsemilla As Boolean
Set db=ss.CurrentDatabase
Set ndsel=db.Search("Form='reiniciarcoleccion123'",Nothing,0) 'This line is for reset the collection
If coleccion.Count<= numdocumentos Then
Set seleccionaleatoriapreguntas=coleccion
Exit Function
End If
For i=1 To numdocumentos
If i=1 Then
usarsemilla=True
Else
usarsemilla=False
End If
docseleccionado=aleatorioEntero(1, Cint(coleccion.Count),usarsemilla)
'Msgbox " docseleccionado: "+Cstr(docseleccionado)
Call ndsel.AddDocument( coleccion.GetNthDocument(docseleccionado) )
Call coleccion.DeleteDocument( coleccion.GetNthDocument(docseleccionado) )
Next
Set seleccionaleatoriapreguntas=ndsel
Exit Function
label:
Msgbox "Error seleccionaleatoriapreguntas: "+Error+" Línea: "+Cstr(Erl)
Exit Function
End Function