【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《VB小学数学四则运算程序代码》,欢迎阅读!
Option Base 1 '标识数组下标从1开始 Dim x, y, z As Integer
Private Sub Command1_Click() Dim a(4) As String Dim b As Integer
Text1.Text = Int(10 * Rnd + 0) '文本框1中随机产生0 - 9中的一个数 a(1) = "+" a(2) = "-" a(3) = "*" a(4) = "/"
b = Int(4 * Rnd + 1)
Label1.Caption = a(b) '标签1随机产生“加”、“减”、“乘”、“除”号 If Label1.Caption = a(4) Then
Text2.Text = Int(9 * Rnd + 1) '如果标签1出现的是“/”号,则文本框2随机产生1-9中的一个数 Else
Text2.Text = Int(10 * Rnd + 0) '如果不是则文本框2随机产生0-9中的一个数 End If
Text3.SetFocus End Sub
Private Sub Command2_Click() Dim c As Single
If IsNumeric(Text3.Text) = False Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "提示" '如果文本框3输入的不是数字或没有输入,则提示“请输入数字!” Text3.Text = "" Text3.SetFocus Else
Select Case Label1.Caption Case "+"
c = Val(Text1.Text) + Val(Text2.Text) Case "-"
c = Val(Text1.Text) - Val(Text2.Text) Case "*"
c = Val(Text1.Text) * Val(Text2.Text) Case "/"
c = Val(Text1.Text) / Val(Text2.Text) End Select
If Text3.Text = c Then
MsgBox "恭喜你,回答正确!", vbOKOnly + vbInformation, "提示" x = x + 1
Text4.Text = x z = z + 10 Text6.Text = z Else
MsgBox "回答错误!" & " " & "正确结果为" & c, vbOKOnly + vbCritical, "提示" y = y + 1
Text5.Text = y z = z - 10 Text6.Text = z End If End If End Sub
Private Sub Form_Load() Randomize End Sub
Private Sub Label1_Change() Text3.Text = "" End Sub
Private Sub Text1_Change() Text3.Text = ""
End Sub
Private Sub Text2_Change() Text3.Text = "" End Sub
本文来源:https://www.wddqxz.cn/da3d05ea81c758f5f61f67ed.html