vb题,三个标签,一个文本框,两个命令按钮,编写一计算机自动出题并判断对错的程序,单击出题按钮,

2024年11月19日 20:37
有1个网友回答
网友(1):

Private Sub command1_click() '出题
Randomize
Label1 = Int(Rnd * 9) + 1 '如果要两位数就把9改成99
Randomize
Label3 = Int(Rnd * 9) + 1
Select Case Int(Rnd * 4) + 1
Case 1
Label2 = "+"
Case 2
Label2 = "-"
Case 3
Label2 = "×"
Case 4
Label2 = "÷"
End Select
End Sub

Private Sub Command2_Click()
Select Case Label2.Caption
Case "+"
If Text1 = CInt(Label1) + CInt(Label3) Then
MsgBox "正确"
Else
MsgBox "错误"
End If
Case "-"
If Text1 = CInt(Label1) - CInt(Label3) Then
MsgBox "正确"
Else
MsgBox "错误"
End If
Case "×"
If Text1 = CInt(Label1) * CInt(Label3) Then
MsgBox "正确"
Else
MsgBox "错误"
End If
Case "÷"
If Text1 = CInt(Label1) / CInt(Label3) Then
MsgBox "正确"
Else
MsgBox "错误"
End If
End Select
End Sub