VB脚本编写的小题库程序

来源:互联网 发布:世界网络发展史 编辑:程序博客网 时间:2024/04/29 07:28


一、程序运行截图

   

二、主要思想

  就是把Excel也当成一个数据库,只不过这个数据库只支持文本。程序可以改变和增加Excel里面的题目内容,题库也会相应增大,注意总题数也要改成和实际题目数目相应的数字。

 本程序的Excel结构如下:


三、脚本内容

Option Explicit

Public currentNum, questionNum, totalNum As Integer

Public optionValue, correctAnswer As String

 

 

Private Sub CommandButtonAnswer_Click()

 

 

correctAnswer = Worksheets("Sheet1").Cells(questionNum, 6)

 

 If OptionButtonAnswerA Then

   optionValue = "A"

 

ElseIf OptionButtonB Then

   optionValue = "B"

 

ElseIf OptionButtonC Then

   optionValue = "C"

ElseIf OptionButtonD Then

   optionValue = "D"

   

End If

   

If (StrComp(optionValue, correctAnswer) = 0) Then

LabelHint.Caption = "回答正确"

Else

LabelHint.Caption = "回答错误,正确答案是" + correctAnswer

End If

 

End Sub

 

Private Sub CommandButtonNext_Click()

If CheckBoxRnd Then

currentNum = Int((totalNum * Rnd) + 1)

questionNum = currentNum + 1

Else

currentNum = (currentNum + 1) Mod totalNum

If currentNum <> 0 Then

questionNum = currentNum + 1

Else

questionNum = totalNum + 1

End If

 

End If

LabelTitle.Caption = Worksheets("Sheet1").Cells(questionNum, 1)

 OptionButtonAnswerA.Caption = "A." + Worksheets("Sheet1").Cells(questionNum, 2)

 OptionButtonB.Caption = "B." + Worksheets("Sheet1").Cells(questionNum, 3)

 OptionButtonC.Caption = "C." + Worksheets("Sheet1").Cells(questionNum, 4)

 OptionButtonD.Caption = "D." + Worksheets("Sheet1").Cells(questionNum, 5)

 

 

LabelHint.Caption = ""

 

 OptionButtonAnswerA = False

 OptionButtonB = False

 OptionButtonC = False

 OptionButtonD = False

End Sub

 

Private Sub UserForm_Activate()

 

End Sub

 

Private Sub UserForm_Click()

 

End Sub

Private Sub UserForm_Initialize()

currentNum = 1

questionNum = currentNum + 1

 

totalNum = CInt(Worksheets("Sheet1").Cells(2, 7))

 

optionValue = ""

correctAnswer = ""

LabelHint = ""

 

 LabelTitle.Caption = Worksheets("Sheet1").Cells(questionNum, 1)

 OptionButtonAnswerA.Caption = "A." + Worksheets("Sheet1").Cells(questionNum, 2)

 OptionButtonB.Caption = "B." + Worksheets("Sheet1").Cells(questionNum, 3)

 OptionButtonC.Caption = "C." + Worksheets("Sheet1").Cells(questionNum, 4)

 OptionButtonD.Caption = "D." + Worksheets("Sheet1").Cells(questionNum, 5)

 

 

End Sub

 


附:脚本下载地址 http://download.csdn.net/detail/ciel_arc/9428962

0 0
原创粉丝点击