考试随机出题程序_第1页
考试随机出题程序_第2页
考试随机出题程序_第3页
考试随机出题程序_第4页
考试随机出题程序_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、考试随机出题程序-VB课程设计实验报告这是一个随机从题库读取题目并判断是否做对了的程序一.程序简介:1. 双击启动程序后,会出现开始与结束两个按钮.单击开始按钮,选择做题模式:选择题模式,或者填空题模式.单击选择题模式后,将开始做选择题.一共20道选择题.在规定的时间内完成所给的题目,程序能自动判断对错.填空题模式也是一样.2. 程序模块介绍:主程序背景调用了图片 ”课程设计1.jpeg”3. 源代码解释在PUBLIC中,我把T(20)定义为boolean型,这样的好处是可以判断一道题是否已经出过了,起始为false,默认为没有出现过这道题.出现后将这道题的T(i)设置为TRUE,这样就能与没

2、有出过的题区分开来.在确定的button中,我用了一个for 循环来判断用户输入的答案是否与数据库里的答案相同.为了能访问数据库,我用了data控件来与access数据库连接.数据库路径使用的是相对路径,这样做的好处是无论程序放在哪个目录下都能正确的读取数据库中的内容.代码中的整型变量n为做对题目的数量,整型变量a为累加器,每次加1,直到满20道题.结束累加,并判断正确题数的个数.随机函数前使用了randomize,利用系统时间对随机函数的种子进行初始化.timer初始化时enabled=false,当选择好做题类型后开始计时.在做第一道题前做了一个用户是否操作为空,如果没有任何输入,就返回最

3、开始,并提示用户重新输入一个答案.所有的变量定义在PUBLIC中,并为整型变量,便于使用.4. 附截图两个 5. 附源代码:Option ExplicitDim i, n, m, max, min, x, j, a, timex, sec, total, tiankongti As IntegerDim T(20) As BooleanPrivate Sub Command1_Click()Timer1.Enabled = True For i = 0 To 3 If Option1(i).Value = True Then j = i + 1 n = n + 1 Exit For End I

4、f End If If Option1(0).Value = False And Option1(1).Value = False And Option1(2).Value = False And Option1(3).Value = False Then MsgBox "至少选择一个选项" Exit Sub End If Next i If Not a = max - 1 Then a = a + 1 ElseIf a >= max - 1 Then If n >= 18 Then MsgBox "题目已做完" & "正确

5、的数目为" & n & "错了" & max - n & "你真聪明啊!" Else MsgBox "题目已做完" & "正确的数目为" & n & "错了" & max - n & "你还需努力啊!" End If Timer1.Enabled = False sec = 0 Label9.Caption = "" i = 0 a = 0 n = 0 m = 0 x = 0

6、 Text1.Visible = False Text2.Visible = False Text3.Visible = False Text4.Visible = False Text5.Visible = False Text6.Visible = False Command1.Visible = False Command4.Visible = False Command5.Visible = False Command6.Visible = False Command2.Visible = True Option1(0).Visible = False Option1(1).Visib

7、le = False Option1(2).Visible = False Option1(3).Visible = False Label1.Visible = False Label2.Visible = False Label3.Visible = False Label4.Visible = False Label5.Visible = False Label6.Visible = False Label7.Visible = False Label8.Visible = False For x = 0 To 20 T(x) = False Next x Exit Sub End If

8、countnum: Randomize x = Int(max - min) * Rnd() + min) If T(x) Then GoTo countnum End If T(x) = True For m = 0 To x - 1 Next mEnd SubPrivate Sub Command2_Click() timex = 60 Command4.Visible = True Command5.Visible = True max = 20 min = 0 Randomize x = Int(max - min) * Rnd() + min) T(x) = True For m =

9、 0 To x - 1 Next mEnd SubPrivate Sub Command3_Click() Unload Form1End SubPrivate Sub Command4_Click()Timer1.Enabled = TrueText1.Visible = TrueText2.Visible = TrueText3.Visible = TrueText4.Visible = TrueText5.Visible = TrueCommand1.Visible = TrueOption1(0).Visible = TrueOption1(1).Visible = TrueOptio

10、n1(2).Visible = TrueOption1(3).Visible = TrueLabel1.Visible = TrueLabel2.Visible = TrueLabel3.Visible = TrueLabel4.Visible = TrueLabel5.Visible = TrueLabel6.Visible = TrueLabel7.Visible = TrueCommand2.Visible = FalseCommand5.Visible = FalseEnd SubPrivate Sub Command5_Click()Timer1.Enabled = TrueText

11、1.Visible = TrueText2.Visible = TrueText3.Visible = TrueText4.Visible = TrueText5.Visible = TrueCommand1.Visible = FalseCommand2.Visible = FalseCommand4.Visible = FalseCommand6.Visible = TrueLabel5.Visible = TrueLabel6.Visible = TrueLabel7.Visible = TrueLabel8.Visible = TrueText6.Visible = TrueEnd S

12、ubPrivate Sub Command6_Click()If Text6.Text = "" ThenMsgBox "请输入答案"GoTo hereEnd Ifn = n + 1End IfIf Not a = max - 1 Then a = a + 1 ElseIf a >= max - 1 Then If n >= 18 Then MsgBox "题目已做完" & "正确的数目为" & n & "错了" & max - n & &qu

13、ot;你真聪明啊!" Else MsgBox "题目已做完" & "正确的数目为" & n & "错了" & max - n & "你还需努力啊!" End If Timer1.Enabled = False sec = 0 Label9.Caption = "" i = 0 a = 0 n = 0 m = 0 x = 0 Text1.Visible = False Text2.Visible = False Text3.Visible = Fa

14、lse Text4.Visible = False Text5.Visible = False Text6.Visible = False Command1.Visible = False Command4.Visible = False Command5.Visible = False Command6.Visible = False Command2.Visible = True Label5.Visible = False Label7.Visible = False Label8.Visible = False For x = 0 To 20 T(x) = False Next x E

15、xit Sub End If Text6.Text = ""countnum: Randomize x = Int(max - min) * Rnd() + min) If T(x) Then GoTo countnum End If T(x) = True For m = 0 To x - 1 Next mhere:End SubPrivate Sub Form_Load()Text1.Visible = FalseText2.Visible = FalseText3.Visible = FalseText4.Visible = FalseText5.Visible =

16、FalseCommand1.Visible = FalseLabel1.Visible = FalseLabel2.Visible = FalseLabel3.Visible = FalseLabel4.Visible = FalseLabel5.Visible = FalseLabel6.Visible = FalseLabel7.Visible = FalseOption1(0).Visible = FalseOption1(1).Visible = FalseOption1(2).Visible = FalseOption1(3).Visible = FalseTimer1.Enable

17、d = FalseEnd SubPrivate Sub Timer1_Timer()If sec = 0 Then sec = 1total = timex - secLabel9.Caption = "请在" & total & "秒内做完"sec = sec + 1If total = 0 Then If n >= 18 Then MsgBox "时间到了!" & "题目已做完" & "正确的数目为" & n & "错了&quo

18、t; & max - n & "你真聪明啊!" Else MsgBox "时间到了!" & "题目已做完" & "正确的数目为" & n & "错了" & max - n & "你还需努力啊!" End If Timer1.Enabled = False sec = 0 Label9.Caption = "" i = 0 a = 0 n = 0 m = 0 x = 0 Text1.Visible = False Text2.

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论