您的位置:首页 > 编程语言 > VB

VB脚本编写的小题库程序

2016-02-07 18:54 501 查看


一、程序运行截图

   


二、主要思想

  就是把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.c
4000
sdn.net/detail/ciel_arc/9428962
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: