記錄集內隨機取記錄的代碼
<%
'Movingtorandomrecord-StevenJones'Extension
IfNot(記錄集名稱.bofand記錄集名稱.eof)Then
'resetthecursortothebeginning
If(記錄集名稱.CursorType>0)Then
記錄集名稱.MoveFirst
Else
記錄集名稱.Requery
EndIf
記錄集名稱_totalrn=-1
記錄集名稱_totalrn=記錄集名稱.RecordCount'onyworksonsomerecordsets,butmuchfaster
If(記錄集名稱_totalrn=-1)Then'andifitdidn'twork,westillhavetocounttherecords.
'countthetotalrecordsbyiteratingthroughtherecordset
記錄集名稱_totalrn=0
While(Not記錄集名稱.EOF)
記錄集名稱_totalrn=記錄集名稱_totalrn+1
記錄集名稱.MoveNext
Wend
'resetthecursortothebeginning
If(記錄集名稱.CursorType>0)Then
記錄集名稱.MoveFirst
Else
記錄集名稱.Requery
EndIf
EndIf
'nowdofinaladjustments,andmovetotherandomrecord
記錄集名稱_totalrn=記錄集名稱_totalrn-1
If記錄集名稱_totalrn>0Then
Randomize
記錄集名稱.MoveInt((記錄集名稱_totalrn+1)*Rnd)
EndIf
EndIf
'alldone;youshouldalwayscheckforanemptyrecordsetbeforedisplayingdata
%>