VB答题系统制作教程.docx
- 文档编号:12994229
- 上传时间:2023-06-10
- 格式:DOCX
- 页数:16
- 大小:3.05MB
VB答题系统制作教程.docx
《VB答题系统制作教程.docx》由会员分享,可在线阅读,更多相关《VB答题系统制作教程.docx(16页珍藏版)》请在冰点文库上搜索。
VB答题系统制作教程
VB答题系统制作图文教程
1、打开VisualBasic6.0企业版程序,选择创建exe文件
2、创建后,根据自己的需求设置窗口大小,窗口名称等属性值。
如:
3、在窗口上放置四个按钮(commandButton1-4)控件、两个标签(Label1-2)控件、一个(TextBox1)控件、十个[TextBox(1-10)]控件和两个(Frame1-2)控件。
如图:
4、将各个控件的属性值设置如下:
控件名
属性值
Label1
1
Label2
第题
Command1
最前一题
Command2
上一题
Command3
下一题
Command4
最后一题
Option1
(1)
A
Option1
(2)
B
Option1(3)
C
Option1(4)
D
Frame1
题目区
Frame2
答题区
Text1
MultiLine=true;ScrollBars=2
如图下:
6、在所在工程文件目录下创建一个新文件夹,命名为question;同时再创建一个文件夹,命名为answer。
如图:
7、在question文件夹中创建文本文档,命名为1-10,题目以及选项都需输入。
8、在answer文件中创建文本文档,命名为1-10,所对应的答案按序号入座。
9、双击窗体,输入以下代码:
'______________________________________________________________________________
PrivateSubForm_Load()
Text1.Text=""'卸载Text1的文本内容
DimLstrAsString'定义数据类型
OpenApp.Path+"\question\"&Label1.Caption&".txt"ForInputAs#1'读取文本文档
DoWhileNotEOF
(1)
LineInput#1,Lstr
IfLstr<>""Then
Text1.Text=Text1.Text&Lstr&vbCrLf
EndIf
Loop
Close#1
Fori=1To10
Text2(i).Text=""
Nexti
Command1.Enabled=False'第一题时前两个按钮失效
Command2.Enabled=False
EndSub
'______________________________________________________________________________
PrivateSubCommand1_Click()
Fori=1To4
Option1(i).ForeColor=vbBlack
Option1(i).Value=False
Nexti
Label1.Caption=1
Command1.Enabled=False:
Command2.Enabled=False:
Command3.Enabled=True:
Command4.Enabled=True
IfText2(Label1.Caption).Text<>""Then
Fori=1To4
IfText2(Label1.Caption).Text=Option1(i).CaptionThen
Option1(i).ForeColor=vbRed
Option1(i).Value=True
EndIf
Nexti
EndIf
Text1.Text=""
DimLstrAsString
OpenApp.Path+"\question\"&Label1.Caption&".txt"ForInputAs#1
DoWhileNotEOF
(1)
LineInput#1,Lstr
IfLstr<>""Then
Text1.Text=Text1.Text&Lstr&vbCrLf
EndIf
Loop
Close#1
EndSub
'______________________________________________________________________________
PrivateSubCommand2_Click()
Fori=1To4
Option1(i).ForeColor=vbBlack
Option1(i).Value=False
Nexti
DimXAsInteger
X=Val(Label1.Caption):
X=X-1:
Label1.Caption=X
IfX>1AndX<10ThenCommand1.Enabled=True:
Command2.Enabled=True:
Command3.Enabled=True:
Command4.Enabled=True
IfX=1ThenCommand1.Enabled=False:
Command2.Enabled=False
IfX=10ThenCommand3.Enabled=False:
Command4.Enabled=False
IfText2(Label1.Caption).Text<>""Then
Fori=1To4
IfText2(Label1.Caption).Text=Option1(i).CaptionThen
Option1(i).ForeColor=vbRed
Option1(i).Value=True
EndIf
Nexti
EndIf
Text1.Text=""
DimLstrAsString
OpenApp.Path+"\question\"&Label1.Caption&".txt"ForInputAs#1
DoWhileNotEOF
(1)
LineInput#1,Lstr
IfLstr<>""Then
Text1.Text=Text1.Text&Lstr&vbCrLf
EndIf
Loop
Close#1
EndSub
'______________________________________________________________________________
PrivateSubCommand3_Click()
Fori=1To4
Option1(i).ForeColor=vbBlack
Option1(i).Value=False
Nexti
DimXAsInteger
X=Val(Label1.Caption):
X=X+1:
Label1.Caption=X
IfX>1AndX<10ThenCommand1.Enabled=True:
Command2.Enabled=True:
Command3.Enabled=True:
Command4.Enabled=True
IfX=1ThenCommand1.Enabled=False:
Command2.Enabled=False
IfX=10ThenCommand3.Enabled=False:
Command4.Enabled=False
IfText2(Label1.Caption).Text<>""Then
Fori=1To4
IfText2(Label1.Caption).Text=Option1(i).CaptionThen
Option1(i).ForeColor=vbRed
Option1(i).Value=True
EndIf
Nexti
EndIf
Text1.Text=""
DimLstrAsString
OpenApp.Path+"\question\"&Label1.Caption&".txt"ForInputAs#1
DoWhileNotEOF
(1)
LineInput#1,Lstr
IfLstr<>""Then
Text1.Text=Text1.Text&Lstr&vbCrLf
EndIf
Loop
Close#1
EndSub
'______________________________________________________________________________
PrivateSubCommand4_Click()
Fori=1To4
Option1(i).ForeColor=vbBlack
Option1(i).Value=False
Nexti
Label1.Caption=10
Command1.Enabled=True:
Command2.Enabled=True:
Command3.Enabled=False:
Command4.Enabled=False
IfText2(Label1.Caption).Text<>""Then
Fori=1To4
IfText2(Label1.Caption).Text=Option1(i).CaptionThen
Option1(i).ForeColor=vbRed
Option1(i).Value=True
EndIf
Nexti
EndIf
Text1.Text=""
DimLstrAsString
OpenApp.Path+"\question\"&Label1.Caption&".txt"ForInputAs#1
DoWhileNotEOF
(1)
LineInput#1,Lstr
IfLstr<>""Then
Text1.Text=Text1.Text&Lstr&vbCrLf
EndIf
Loop
Close#1
EndSub
'______________________________________________________________________________
PrivateSubOption1_Click(IndexAsInteger)
Fori=1To4
Option1(i).ForeColor=vbBlack
Nexti
a=Index
Option1(a).Value=True
Option1(a).ForeColor=vbRed
Text2(Label1.Caption).Text=Option1(a).Caption
EndSub
'______________________________________________________________________________
PrivateSubText2_Change(IndexAsInteger)
DimsAsInteger
s=0
Fori=1To10
IfText2(i).Text=""ThenExitSub
Nexti
message=MsgBox("答题完毕!
是否结分?
",vbOKCancel,"VB答题系统")
Ifmessage=vbOKThen
Fori=1To10
OpenApp.Path+"\answer\"&i&".txt"ForInputAs#1
LineInput#1,Lstr
IfText2(i).Text=LstrThen
s=s+10
EndIf
Close#1
Nexti
EndIf
MsgBox"得分"&s
end
EndSub
'______________________________________________________________________________
10、测试运行。
如图所示:
10、设置工程属性:
如图:
11、生成exe文件。
12、在windows环境下的运行。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB 答题 系统 制作 教程