Set CRS = SADOCONN.Execute("Select * From Exam_ThemeChapter Order By Id")
    For i = 1 To CRS.RecordCount
    Set TRS = SADOCONN.Execute("Select Model,ThemeChapter,ThemeFraction,SelectContent From Exam_MContent Where Model='" & Model & "' And ThemeChapter=" & i)
    If Not TRS.EOF Then TRS.MoveLast
    If Not TRS.BOF Then TRS.MoveFirst        ReDim ThemeContent(i)        ThemeContent(i) = TRS("SelectContent")
    If ThemeContent(i) > 0 Then
        Randomize
        r = Rnd
               Set IRS = SADOCONN.Execute("Select Top " & ThemeContent(i) & " ThemeID From Exam_Theme Where ThemeChapter =" & i & " Order By Rnd(" & r & "-ThemeID)")
        Set SRS = SADOCONN.Execute("Select * From Exam_ThemePaper")
        For j = 1 To IRS.RecordCount
            ReDim sSelection(j)
            sSelection(j) = IRS(0)
        
            szSQL = "Insert Into Exam_ThemePaper(ExamID,ThemeID,ThemeFraction,ExamResultTime) Values (" & SRS.RecordCount + j & "," & sSelection(j) & "," & TRS("ThemeFraction") & "," & studentIDN & ")"
            SADOCONN.Execute szSQL
                        IRS.MoveNext
                        Debug.Print sSelection(j)
                        Debug.Print r
                        Debug.Print ThemeContent(i)
        Next j
    End If Next i这段代码中当i循环至2以后rnd得不到随机数,sSelection(j)是连续的,请高手帮忙

解决方案 »

  1.   

    参考这个吧
    http://blog.csdn.net/vbman2003/archive/2007/08/25/1758397.aspx
      

  2.   

    是不是应该如下 :
    ReDim sSelection(1 to IRS.RecordCount)
    For j = 1 To IRS.RecordCount 
        'ReDim sSelection(j) '这个要在循环外 
        sSelection(j) = IRS(0) 
        szSQL = "Insert Into Exam_ThemePaper(ExamID,ThemeID,ThemeFraction,ExamResultTime) Values (" & SRS.RecordCount + j & "," & sSelection(j) & "," & TRS("ThemeFraction") & "," & studentIDN & ")" 
        SADOCONN.Execute szSQL 
        IRS.MoveNext 
        Debug.Print sSelection(j) 
        Debug.Print r 
        Debug.Print ThemeContent(i) 
    Next j 
      

  3.   

    vbman2003兄这种方法我试过,也不行,急啊。