怎么用VB做一个四则运算的程序

 我来答
数学与计算机编程
2019-06-12 · TA获得超过2160个赞
知道大有可为答主
回答量:2312
采纳率:80%
帮助的人:572万
展开全部

Dim m As Integer, n As Integer, Operator As String

Private Sub Command1_Click()

Static Counter As Integer, Right_num As Integer, Error_num As Integer

If Val(Text5.Text) = Operation(m, n) Then

Right_num = Right_num + 1

List1.AddItem m & Operator & n & "=" & Text5.Text & Space(2) & "√"

Else

Error_num = Error_num + 1

List1.AddItem m & Operator & n & "=" & Text5.Text & Space(2) & "×"

End If

Text1.Text = Right_num + Error_num

Text2.Text = Right_num

Text3.Text = Error_num

Text4.Text = Int(Right_num / (Right_num + Error_num) * 100 + 0.5)

Text5.Text = ""

Text5.SetFocus

GenerativeFormulas

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Form_Activate()

Text5.Text = ""

Text5.SetFocus

GenerativeFormulas

End Sub

Private Function Operation(ByVal x As Integer, ByVal y As Integer) As Integer

Select Case Operator

Case "÷"

Operation = x / y

Case "﹣"

Operation = x - y

Case "+"

Operation = x + y

Case "×"

Operation = x * y

End Select

End Function

Private Sub GenerativeFormulas()

Randomize

m = Int(Rnd * 10 + 1)

n = Int(Rnd * 10 + 1)

If m Mod n = 0 Then

Operator = "÷"

ElseIf m >= n Then

Operator = "﹣"

ElseIf Rnd > 0.5 Then

Operator = "+"

Else

Operator = "×"

End If

Label5.Caption = m & Operator & n & "="

End Sub

界面设计:


运行效果:

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式