记录集内随机取记录的代码
<%
'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
%>