代码与下:
Dim arr(1 To 10, 1 To 5) As String
’定义二维文本数组,用于存放第1题到第10题:题目和ABCD四个待选答案。Dim ls, zq As String
’临时文本(用于随机调整四个备选答案顺序)和正确文本。
Dim a, b, c
’定义三个计算器。
Private Sub CommandButton5_Click()
’复位或者下一题按钮。
Label6.Caption = "" ’正确统计清0。
If a = 0 Then
arr(1, 1) = "1+1"
arr(1, 2) = "2"
arr(1, 3) = "3"
arr(1, 4) = "4"
arr(1, 5) = "5"
arr(2, 1) = "1+3" arr(2, 2) = "4"
arr(2, 3) = "5"
arr(2, 4) = "7"
arr(2, 5) = "3"
arr(3, 1) = "3+4"
arr(3, 2) = "7"
arr(3, 3) = "6"
arr(3, 4) = "9"
arr(3, 5) = "5"
arr(4, 1) = "5+4"
arr(4, 2) = "9"
arr(4, 3) = "10"
arr(4, 4) = "11"
arr(4, 5) = "8"
arr(5, 1) = "2+7"
arr(5, 2) = "9"
arr(5, 3) = "8"
arr(5, 4) = "10"
arr(5, 5) = "7"
arr(6, 1) = "3+5"
arr(6, 2) = "8"
arr(6, 3) = "7"
arr(6, 4) = "9"
arr(6, 5) = "10"
arr(7, 1) = "7+4"
arr(7, 2) = "11"
arr(7, 3) = "12"
arr(7, 4) = "10"
arr(7, 5) = "9"
arr(8, 1) = "8+4"
arr(8, 2) = "12 "
arr(8, 3) = "13"
arr(8, 4) = "10"
arr(8, 5) = "11"
arr(9, 1) = "9+3"
arr(9, 2) = "12"
arr(9, 3) = "11"
arr(9, 4) = "13"
arr(9, 5) = "14"
arr(10, 1) = "6+2"
arr(10, 2) = "8"
arr(10, 3) = "9"
arr(10, 4) = "10"
arr(10, 5) = "7"
End If
a = a + 1
If a = 11 Then
CommandButton5.Caption = "重新开始" Label1.Caption = ""
Label2.Caption = ""
Label3.Caption = ""
Label4.Caption = ""
Label5.Caption = ""
a = 0
c = 0
Label7.Caption = ""
Else
CommandButton1.Caption = "A" CommandButton2.Caption = "B" CommandButton3.Caption = "C" CommandButton4.Caption = "D" CommandButton5.Caption = "下一题" Randomize (Timer)
b = Int(3 * Rnd + 3)
ls = arr(a, 3)
arr(a, 3) = arr(a, b)
arr(a, b) = ls
b = Int(4 * Rnd + 2)
ls = arr(a, 2)
arr(a, 2) = arr(a, b)
arr(a, b) = ls
Label1.Caption = arr(a, 1)
Label2.Caption = "A、" & arr(a, 2) Label3.Caption = "B、" & arr(a, 3) Label4.Caption = "C、" & arr(a, 4) Label5.Caption = "D、" & arr(a, 5)
If b = 2 Then zq = "A"
If b = 3 Then zq = "B"
If b = 4 Then zq = "C"
If b = 5 Then zq = "D"
End If
End Sub
Private Sub CommandButton1_Click() If CommandButton1.Caption = "A" Then If zq = "A" Then
CommandButton1.Caption = "正确!"
c = c + 1
Label7.Caption = "答对:" & c
Else
CommandButton1.Caption = "错误!" Label6.Caption = "正确答案:" & zq End If
CommandButton2.Caption = "" CommandButton3.Caption = "" CommandButton4.Caption = ""
End If
End Sub
Private Sub CommandButton2_Click() If CommandButton2.Caption = "B" Then If zq = "B" Then
CommandButton2.Caption = "正确!"
c = c + 1
Label7.Caption = "答对:" & c
Else
CommandButton2.Caption = "错误!" Label6.Caption = "正确答案:" & zq End If
CommandButton1.Caption = "" CommandButton3.Caption = "" CommandButton4.Caption = ""
End If
End Sub
Private Sub CommandButton3_Click() If CommandButton3.Caption = "C" Then If zq = "C" Then
CommandButton3.Caption = "正确!"
c = c + 1
Label7.Caption = "答对:" & c
Else
CommandButton3.Caption = "错误!" Label6.Caption = "正确答案:" & zq End If
CommandButton2.Caption = "" CommandButton1.Caption = "" CommandButton4.Caption = ""
End If
End Sub
Private Sub CommandButton4_Click() If CommandButton4.Caption = "D" Then If zq = "D" Then
CommandButton4.Caption = "正确!"
c = c + 1
Label7.Caption = "答对:" & c
Else
CommandButton4.Caption = "错误!" Label6.Caption = "正确答案:" & zq End If
CommandButton2.Caption = "" CommandButton3.Caption = "" CommandButton1.Caption = ""
End If
End Subarr(2, 4) = "7"
arr(2, 5) = "3"
arr(3, 1) = "3+4"
arr(3, 2) = "7"
arr(3, 3) = "6"
arr(3, 4) = "9"
arr(3, 5) = "5"
arr(4, 1) = "5+4"
arr(4, 2) = "9"
arr(4, 3) = "10"
arr(4, 4) = "11"
arr(4, 5) = "8"
arr(5, 1) = "2+7"
arr(5, 2) = "9"
arr(5, 3) = "8"
arr(5, 4) = "10"
arr(5, 5) = "7"
arr(6, 1) = "3+5"
arr(6, 2) = "8"
arr(6, 3) = "7"
arr(6, 4) = "9"
arr(6, 5) = "10"
arr(7, 1) = "7+4"
arr(7, 2) = "11"
arr(7, 3) = "12"
arr(7, 4) = "10"
arr(7, 5) = "9"
arr(8, 1) = "8+4"
arr(8, 2) = "12 "
arr(8, 3) = "13"
arr(8, 4) = "10"
arr(8, 5) = "11"
arr(9, 1) = "9+3"
arr(9, 2) = "12"
arr(9, 3) = "11"
arr(9, 4) = "13"
arr(9, 5) = "14"
arr(10, 1) = "6+2"
arr(10, 2) = "8"
arr(10, 3) = "9"
arr(10, 4) = "10"
arr(10, 5) = "7"
End If
a = a + 1
If a = 11 Then
CommandButton5.Caption = "重新开始" Label1.Caption = ""
Label2.Caption = ""
Label3.Caption = ""
Label4.Caption = ""
Label5.Caption = ""
a = 0
c = 0
Label7.Caption = ""
Else
CommandButton1.Caption = "A" CommandButton2.Caption = "B" CommandButton3.Caption = "C" CommandButton4.Caption = "D" CommandButton5.Caption = "下一题" Randomize (Timer)
b = Int(3 * Rnd + 3)
ls = arr(a, 3)
arr(a, 3) = arr(a, b)
arr(a, b) = ls
b = Int(4 * Rnd + 2)
ls = arr(a, 2)
arr(a, 2) = arr(a, b)
arr(a, b) = ls
Label1.Caption = arr(a, 1)
Label2.Caption = "A、" & arr(a, 2) Label3.Caption = "B、" & arr(a, 3) Label4.Caption = "C、" & arr(a, 4) Label5.Caption = "D、" & arr(a, 5)
If b = 2 Then zq = "A"
If b = 3 Then zq = "B"
If b = 4 Then zq = "C"
If b = 5 Then zq = "D"
End If
End Sub
Private Sub CommandButton3_Click() If CommandButton3.Caption = "C" Then If zq = "C" Then
CommandButton3.Caption = "正确!"
c = c + 1
Label7.Caption = "答对:" & c
Else
CommandButton3.Caption = "错误!" Label6.Caption = "正确答案:" & zq End If
CommandButton2.Caption = "" CommandButton1.Caption = "" CommandButton4.Caption = ""
End If
End Sub
Private Sub CommandButton4_Click() If CommandButton4.Caption = "D" Then If zq = "D" Then
CommandButton4.Caption = "正确!"
c = c + 1
Label7.Caption = "答对:" & c
Else
CommandButton4.Caption = "错误!" Label6.Caption = "正确答案:" & zq End If
CommandButton2.Caption = "" CommandButton3.Caption = "" CommandButton1.Caption = ""
End If
End Sub