如何用VB实现考试系统里的随机抽取考试试题,没有重复

killrockman 2007-12-04 05:24:59
如何用VB实现考试系统里的随机抽取考试试题,没有重复?!
...全文
546 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
root_mind 2008-01-06
  • 打赏
  • 举报
回复
这个跟vb没关系吧
从数据中读题的时候就随机不就可以了?
用sql 就像一楼的
cike_1111 2007-12-31
  • 打赏
  • 举报
回复
Print List1.ListCount 这句是我用来显示 list项目数的 可以删除

// 打乱顺序后 按照这个顺序(题号 也就是 数据库中的编号)逐个读到程序中 这样就可以避免重复了!

^_^

cike_1111 2007-12-31
  • 打赏
  • 举报
回复
每个不同类型的题目应该是不在一个表单中才对

如:
表单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 Sub

Private Sub Form_Load()
For i = 0 To 99
List1.AddItem i
Next i
List2.Visible = False
Command1.Caption = "打乱顺序"
End Sub


chuting1 2007-12-31
  • 打赏
  • 举报
回复
可以放一个标识字段,用于检查是否已被抽取
KiteGirl 2007-12-31
  • 打赏
  • 举报
回复
我对这个问题专门研究过,请参考我Blog里的“跳蚤算法”。
killrockman 2007-12-30
  • 打赏
  • 举报
回复
楼上的给的 只是简单的 SQL语句 查找。。。
我需要的是如何先判断考生的 类型,然后再根据考生的类型检索对应的题库,生成临时试卷的过程?!
lianzy 2007-12-30
  • 打赏
  • 举报
回复

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

Winters_lee 2007-12-05
  • 打赏
  • 举报
回复
这个和发牌程序差不多,我以前用这个方法做了一个:

如果你有10000个考试题目,那么你可以用

Cint(Rnd()*10000)+1得出一个1~10000的随机数,然后与以前得出的随机数进行比较,发现相同则重新取。

虽然麻烦点,还是可行。
  • 打赏
  • 举报
回复
假设随机考100个题目
select top 100 * from tb where 考试范围条件 order by newid()
killrockman 2007-12-05
  • 打赏
  • 举报
回复
我的想法是先在题库的数据表中检索符合的类型,因为题库是分类的,不同的考生考试的范围也不一样,所以先检索题库,然后再从这些检索出来的符合的类型中再来随机抽取。
不知道是否可行?显示起来是否麻烦?!

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧