版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、考试随机出题程序-VB课程设计实验报告这是一个随机从题库读取题目并判断是否做对了的程序一.程序简介:1. 双击启动程序后,会出现开始与结束两个按钮.单击开始按钮,选择做题模式:选择题模式,或者填空题模式.单击选择题模式后,将开始做选择题.一共20道选择题.在规定的时间内完成所给的题目,程序能自动判断对错.填空题模式也是一样.2. 程序模块介绍:程序制作使用的是Microsoft Visual Studio 6.0,题库采用的是Microsoft access 7.0.该程序所用到的VB控件有command,text,label,timer,data,option.其中data控件是用来与数据库
2、连接的,timer控件是用来计算做题剩余时间的.主程序背景调用了图片 ”课程设计1.jpeg”3. 源代码解释在PUBLIC中,我把T(20)定义为boolean型,这样的好处是可以判断一道题是否已经出过了,起始为false,默认为没有出现过这道题.出现后将这道题的T(i)设置为TRUE,这样就能与没有出过的题区分开来.在确定的button中,我用了一个for 循环来判断用户输入的答案是否与数据库里的答案相同.为了能访问数据库,我用了data控件来与access数据库连接.数据库路径使用的是相对路径,这样做的好处是无论程序放在哪个目录下都能正确的读取数据库中的内容.代码中的整型变量n为做对题目
3、的数量,整型变量a为累加器,每次加1,直到满20道题.结束累加,并判断正确题数的个数.随机函数前使用了randomize,利用系统时间对随机函数的种子进行初始化.timer初始化时enabled=false,当选择好做题类型后开始计时.在做第一道题前做了一个用户是否操作为空,如果没有任何输入,就返回最开始,并提示用户重新输入一个答案.所有的变量定义在PUBLIC中,并为整型变量,便于使用.4. 附截图两个 5. 附源代码:Option ExplicitDim i, n, m, max, min, x, j, a, timex, sec, total, tiankongti As Integer
4、Dim T(20) As BooleanPrivate Sub Command1_Click()Timer1.Enabled = True For i = 0 To 3 If Option1(i).Value = True Then j = i + 1 If j = Data1.Recordset.Fields(truth) Then n = n + 1 Exit For End If End If If Option1(0).Value = False And Option1(1).Value = False And Option1(2).Value = False And Option1(
5、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 题目已做完 & 正确的数目为 & n & 错了 & max - n & 你真聪明啊! Else MsgBox 题目已做完 & 正确的数目为 & n & 错了 & max - n & 你还需努力啊! End If Timer1.Enabled = False sec = 0 Label9.Caption = i = 0
6、 a = 0 n = 0 m = 0 x = 0 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
7、= False Option1(1).Visible = 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) = Fals
8、e Next x Exit Sub End Ifcountnum: 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() +
9、min) T(x) = True For m = 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 = TrueOption
10、1(1).Visible = TrueOption1(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()T
11、imer1.Enabled = TrueText1.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 = TrueT
12、ext6.Visible = TrueEnd SubPrivate Sub Command6_Click()If Text6.Text = ThenMsgBox 请输入答案GoTo hereEnd IfIf Text6.Text = Data1.Recordset.Fields(truthvalue) Thenn = n + 1End IfIf Not a = max - 1 Then a = a + 1 ElseIf a = max - 1 Then If n = 18 Then MsgBox 题目已做完 & 正确的数目为 & n & 错了 & max - n & 你真聪明啊! Else M
13、sgBox 题目已做完 & 正确的数目为 & 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 = False Text4.Visible = False Text5.Visible = False Text6.Visible = False Command1.Visible = False Command4
14、.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 Exit Sub End If Text6.Text = countnum: Randomize x = Int(max - min) * Rnd() + min) If T(x) Then GoTo cou
15、ntnum 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 = FalseCommand1.Visible = FalseLabel1.Visible = FalseLabel2.Visible = FalseLabel3.Visible = FalseLabel4.Visible = Fal
16、seLabel5.Visible = FalseLabel6.Visible = FalseLabel7.Visible = FalseOption1(0).Visible = FalseOption1(1).Visible = FalseOption1(2).Visible = FalseOption1(3).Visible = FalseTimer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()If sec = 0 Then sec = 1total = timex - secLabel9.Caption = 请在 & total & 秒
17、内做完sec = sec + 1If total = 0 Then If n = 18 Then MsgBox 时间到了! & 题目已做完 & 正确的数目为 & 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 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 Label5.Vi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年工业机器人运维服务模式创新
- 护理课件规范标准
- 护理员情绪调节策略
- 热风炉工操作测试考核试卷含答案
- 暗盒生产工班组管理测试考核试卷含答案
- 铁合金炉外法冶炼工岗前技术创新考核试卷含答案
- 石雕工风险评估与管理考核试卷含答案
- 趸船水手发展趋势知识考核试卷含答案
- 美容师安全专项评优考核试卷含答案
- 针制作工岗前工作改进考核试卷含答案
- 2026年有限空间作业人员安全知识考试试题(含答案)
- 2026年天津市高三高考二模英语模拟试卷试题(含答案详解)
- 2026年监理工程师之交通工程目标控制押题模拟附参考答案详解【巩固】
- 广东省广州市增城区2025-2026学年九年级上学期1月期末考试语文试题
- 2026中国卵巢上皮性癌维持治疗专家共识解读
- 眼科中医诊室工作制度
- 阴道镜门诊工作制度
- 2025-2030中国激光脱毛产品市场未来趋势与营销战略规划研究报告
- (正式版)DB50∕T 1915-2025 《电动重型货车大功率充电站建设技术规范》
- 高处作业吊篮安装、拆卸、使用技术规程(2025版)
- 天津市园林建设工程监理用表和质量验收用表(绿表)
评论
0/150
提交评论