VB程序代码:“加减乘除”
这个代码运行只有加法,我希望它还可以同时有“减乘除”,请帮助修改!PublicForm1PublicaAsIntegerPublicbAsIntegerPubliccAs...
这个代码运行只有加法,我希望它还可以同时有“减乘除”,请帮助修改!
Public Form1 Public a As Integer Public b As Integer Public c As Integer Private Sub command1_Click() a = Int(Rnd * 10 + 1) b = Int(Rnd * 10 + 1) Text1.Text = a & "+" & b End Sub Private Sub command2_Click() c = a + b If (Int(Text2.Text) = c) Then MsgBox ("计算正确!") Else MsgBox ("计算错误!") End If End Sub
这是题目: 展开
Public Form1 Public a As Integer Public b As Integer Public c As Integer Private Sub command1_Click() a = Int(Rnd * 10 + 1) b = Int(Rnd * 10 + 1) Text1.Text = a & "+" & b End Sub Private Sub command2_Click() c = a + b If (Int(Text2.Text) = c) Then MsgBox ("计算正确!") Else MsgBox ("计算错误!") End If End Sub
这是题目: 展开
1个回答
展开全部
Private a As Integer
Private b As Integer
Private c As Integer
Private d As Integer
Private Const ds As String = "+-*/"
Private Sub Command1_Click()
a = Int(Rnd * 10 + 1)
b = Int(Rnd * 10 + 1)
d = Int(Rnd * 4 + 1)
Text1.Text = a & Mid(ds, d, 1) & b
End Sub
Private Sub Command2_Click()
Select Case d
Case 1: c = a + b
Case 2: c = a - b
Case 3: c = a * b
Case 4: c = a / b
End Select
If (Int(Text2.Text) = c) Then
MsgBox ("计算正确!")
Else
MsgBox ("计算错误!")
End If
End Sub
除法的不太实用.
有一个改进型的你看下,但超过10了
Private Sub Command1_Click()
d = Int(Rnd * 4 + 1)
If d = 4 Then
a = Int(Rnd * 20 + 10)
b = Int(Rnd * a + 1)
a = b * (a \ b)
Else
b = Int(Rnd * 10 + 1)
a = Int(Rnd * 10 + 1)
End If
Text1.Text = a & Mid(ds, d, 1) & b
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询