Description As String '問題描述
Option(2) As String '備選答案
Answer As Integer '正確答案的序號(0-2)
End Type
Dim Questions(19) As utQuestion, id As Integer, answer As Integer
Private Sub Form_Load()
Dim i As Integer
'問題初始化從下壹行開始
With Questions(0)
.Description = "問題描述內容"
.Option(0) = "備選答案1"
.Option(1) = "備選答案2"
.Option(2) = "備選答案3"
.Answer = 0 ‘按實際情況輸入:0、1、2的其中1個
End With
With Questions(1)
.Description = "問題描述內容"
.Option(0) = "備選答案1"
.Option(1) = "備選答案2"
.Option(2) = "備選答案3"
.Answer = 0 ‘按實際情況輸入:0、1、2的其中1個
End With
With Questions(2)
.Description = "問題描述內容"
.Option(0) = "備選答案1"
.Option(1) = "備選答案2"
.Option(2) = "備選答案3"
.Answer = 0 ‘按實際情況輸入0、1、2
End With
'……
With Questions(19)
.Description = "問題描述內容"
.Option(0) = "備選答案1"
.Option(1) = "備選答案2"
.Option(2) = "備選答案3"
.Answer = 0 ‘按實際情況輸入0、1、2
End With
'問題初始化到上壹行結束
ShowNext 0 '顯示第1個問題
End Sub
Private Sub ShowNext(ByVal Index As Integer)
'改變問題: Index = 0 To 19
Dim i As Integer
With Questions(Index)
AskContent = “1、" & .Description 'AskContent是Label控件的Name
For i = 0 To 2
AnswerItems(i).Value = False
AnswerItems(i).Caption = Chr(i+65) & "、" & .Option(i) 'AnswerItems是Option控件數組的Name
Next
End With
answer = -1
End Sub
Private Sub Answers_Click(Index As Integer)
answer = Index '獲取答案序號
End Sub
Private Sub Submit_Click() 'Submit是CommandButton控件的Name
If id >19 Then
MsgBox "已完成全部題目!"
Exit Sub
End If
If answer < 0 Then
MsgBox "請選擇答案後在單擊確定按鈕!"
Else
If answer = Questions(id).Answer Then
id = id + 1
ShowNext id
Else
MsgBox "回答錯誤,正確答案是" & Choose(Questions(id).Answer+1, "A","B","C") & ""
End If
End If
End Sub