Option Explicit
Dim op, n1, n2, nop, n3
Dim result
Private Sub Command1_Click()
Timer1.Enabled = True
Call cs
Text1.SetFocus
End Sub
Private Sub Command2_Click()
Picture1.Visible = True
Picture2.Visible = True
Label3.Visible = True
End Sub
Private Sub Form_Load()
Picture1.Visible = False
Picture2.Visible = False
Label3.Visible = False
Timer1.Interval = 30
Timer1.Enabled = False
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Val(Text1) = result Then Call cs
Text1.SetFocus
End If
End Sub
Private Sub Timer1_Timer()
Picture1.Move Picture1.Left + 30
If Picture1.Left > Form1.Width Then Timer1.Enabled = False
If Label3.Left > Form1.Width Then Timer1.Enabled = False
Picture2.Move Picture2.Left + 10
If Picture2.Left > Form1.Width Then Timer1.Enabled = False
End Sub
Sub cs()
Randomize
nop = Int(Rnd * 4 + 1)
Select Case nop
Case 1
op = "+"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
Label3.Caption = n1 & "+" & n2 & "="
result = n1 + n2
Case 2
op = "-"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
If n1 < n2 Then n3 = n1: n1 = n2: n2 = n3
Label3.Caption = n1 & "+" & n2 & "="
result = n1 - n2
Case 3
op = "×"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
Label3.Caption = n1 & "+" & n2 & "="
result = n1 * n2
Case 4
op = "÷"
n2 = Int(Rnd * 9 + 1)
n1 = Int(Rnd * 10 + 0) * n2
Label3.Caption = n1 & "+" & n2 & "="
result = n1 / n2
End Select
End Sub
界面如下
主要的目的就是label3中产生一个式子,然后在TEXT1中输入运算结果,然后回车判断,如果是正确的就重新调用一次产生另一条式子,继续判断。可是我的代码不可以判断,要怎么改?我是初学者