I got this code from www.4guysfromrolla.com
it opens up my DB(access right now) and grabs the data, putting it into an array using the GetRows method.
then it calls a function that randomizes the order of that data.
i know the code works, at least the test on the 4guysfromrolla site did.
only I don't know how to get it to work.....How do i get the data out of the array and displayed on my page?
any help or suggestions are greatly appreciated.Code:<%'Open up connection to database... Dim objConn,strConn Set objConn = Server.CreateObject("ADODB.Connection") objConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("TestQuestion.mdb") 'Create a recordset object and grab a query Dim objRS Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open "select questions_ID from questions", objConn 'Create an Array variable and use GetRows Dim aRows aRows = objRS.GetRows() 'Response.Write lbound(aRows) if not (rs.EOF) and not (rs.BOF) then do until objRS.EOF Response.Write objRS.questions_ID & "<br>test.." objRS.MoveNext loop else Response.Write "in the else" end if 'Clean up... objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing Function ReOrderArray2D(ByVal aArray) 'Get the upper and lower bounds from the second 'dimension (the row count)... also, create a temporary 'array, aTmpArray, to hold the reordered values Dim iCount, aTmpArray iCount = UBound(aArray, 2) ReDim aTmpArray(UBound(aArray, 1), UBound(aArray, 2)) Dim iLoop, strIndex, iUpper, iLower iLower = LBound(aArray, 2) For iLoop = iLower to iCount strIndex = strIndex & CStr(iLoop) If iLoop < iCount then strIndex = strIndex & "," Next 'Choose a Random Index Randomize Timer Dim iRnd, aTmp, iTmpUpper, strNewIndex, iInnerLoop Redim aTmp(iCount) 'Loop through the array For iLoop = iLower to iCount iTmpUpper = iCount - iLoop 'Rebuild aTmp, the array of indexes ReDim Preserve aTmp(iTmpUpper) aTmp = split(strIndex, ",") 'Add an element to the temp array... iRnd = Int(Rnd * (iTmpUpper + 1)) For iInnerLoop = LBound(aArray,1) to UBound(aArray,1) aTmpArray(iInnerLoop, iLoop) = aArray(iInnerLoop, aTmp(iRnd)) Next 'Compact aTmp, the array of indexes aTmp(iRnd) = aTmp(iTmpUpper) ReDim Preserve aTmp(iTmpUpper - 1) strIndex = join(aTmp, ",") Next ReOrderArray2D = aTmpArray End Function
Thanks




Reply With Quote