Dim i As Integer '变量 Dim intTmp As Integer '临时变量 Dim subject_id() As Integer '题目编号 Dim subject_name() As Integer '题目标题 Dim intCount As Integer '题目数量 Dim intNum As Integer '要出的题目数量 intNum = 20 '初始化出20道题 Set rs = getRS("select subject_ID,subject_name from subject where 条件") intCount = rs.recordcount ReDim subject_id(intCount) As Integer ReDim subject_name(intCount) As Integer For i = 0 To intCount - 1 subject_id(i) = rs("subject_id") subject_name(i) = rs("subject_name") rs.movenext Next rs.Close If intCount < intNum Then MsgBox "题目不够!" End If '至此,符合条件的题目已经放到数组中了 '出20道不重复的题 For i = 1 To intNum Randomize Timer intTmp = Int(Rnd() * intCount) Debug.Print (subject_id(intTmp) & ":" & subject_name(intTmp)) '每出一道题后,把数组题题后一道题换掉已出题目,数组大小减1,再出后面的题才不会重重 intCount = intCount - 1 subject_id(intTmp) = subject_id(intCount) subject_name(intTmp) = subject_name(intCount) ReDim Preserve subject_id(intCount) As Integer ReDim Preserve subject_name(intCount) As Integer Next
我对这个问题专门研究过,请参考我Blog里的“跳蚤算法”。
每个不同类型的题目应该是不在一个表单中才对如: 表单1 数据库中: 字段1 字段2 字段3 字段4 字段5 .... 题号 题目 选择1 选择2 选择3 .... .....表单2 字段1 字段2 字段3 字段4 字段5 .... 题号 题目 选择1 选择2 选择3 .... ......程序部分: 1个list 思路: 1.选择类型后. if 属于类型1 则:list获取 表单1的 所有题号 到list里>> if 属于类型2 则:list获取 表单1的 所有题号 到list里>> 2.打乱list内 提号的顺序 3.循环list 重0-最后项目 把题目读取到程序下面是一个 打乱 list 顺序的小例题 提供参考: 材料: 2*list 1*command 步骤:>>>放入2个list 和 1个command 到窗体中 >>> 贴代码 看效果 Private Sub Command1_Click() Randomize List2.Clear For i = 0 To List1.ListCount - 1 b = Int(Rnd * (List1.ListCount)) List2.AddItem List1.List(b) List1.RemoveItem b List1.Refresh Next i For i = 0 To List2.ListCount - 1 List1.AddItem List2.List(i) Next i Print List1.ListCount End SubPrivate Sub Form_Load() For i = 0 To 99 List1.AddItem i Next i List2.Visible = False Command1.Caption = "打乱顺序" End Sub
select top 100 * from tb where 考试范围条件 order by newid()
我需要的是如何先判断考生的 类型,然后再根据考生的类型检索对应的题库,生成临时试卷的过程?!
Dim i As Integer '变量
Dim intTmp As Integer '临时变量
Dim subject_id() As Integer '题目编号
Dim subject_name() As Integer '题目标题
Dim intCount As Integer '题目数量
Dim intNum As Integer '要出的题目数量
intNum = 20 '初始化出20道题
Set rs = getRS("select subject_ID,subject_name from subject where 条件")
intCount = rs.recordcount
ReDim subject_id(intCount) As Integer
ReDim subject_name(intCount) As Integer
For i = 0 To intCount - 1
subject_id(i) = rs("subject_id")
subject_name(i) = rs("subject_name")
rs.movenext
Next
rs.Close
If intCount < intNum Then
MsgBox "题目不够!"
End If
'至此,符合条件的题目已经放到数组中了
'出20道不重复的题
For i = 1 To intNum
Randomize Timer
intTmp = Int(Rnd() * intCount)
Debug.Print (subject_id(intTmp) & ":" & subject_name(intTmp)) '每出一道题后,把数组题题后一道题换掉已出题目,数组大小减1,再出后面的题才不会重重
intCount = intCount - 1
subject_id(intTmp) = subject_id(intCount)
subject_name(intTmp) = subject_name(intCount)
ReDim Preserve subject_id(intCount) As Integer
ReDim Preserve subject_name(intCount) As Integer
Next
表单1
数据库中:
字段1 字段2 字段3 字段4 字段5 ....
题号 题目 选择1 选择2 选择3 ....
.....表单2
字段1 字段2 字段3 字段4 字段5 ....
题号 题目 选择1 选择2 选择3 ....
......程序部分:
1个list
思路:
1.选择类型后. if 属于类型1 则:list获取 表单1的 所有题号 到list里>>
if 属于类型2 则:list获取 表单1的 所有题号 到list里>>
2.打乱list内 提号的顺序
3.循环list 重0-最后项目 把题目读取到程序下面是一个 打乱 list 顺序的小例题 提供参考:
材料:
2*list
1*command
步骤:>>>放入2个list 和 1个command 到窗体中
>>> 贴代码 看效果
Private Sub Command1_Click()
Randomize
List2.Clear
For i = 0 To List1.ListCount - 1
b = Int(Rnd * (List1.ListCount))
List2.AddItem List1.List(b)
List1.RemoveItem b
List1.Refresh
Next i
For i = 0 To List2.ListCount - 1
List1.AddItem List2.List(i)
Next i
Print List1.ListCount
End SubPrivate Sub Form_Load()
For i = 0 To 99
List1.AddItem i
Next i
List2.Visible = False
Command1.Caption = "打乱顺序"
End Sub
从数据中读题的时候就随机不就可以了?
用sql 就像一楼的