有没有大神可以帮我用VB做一个简易计算器啊,能加减乘除,退格、倒数等功能就好了,快考试了,好方啊!! 10
1个回答
展开全部
界面上放1个文本框。6个按钮,分别为+、-、*、/、=、C
定义几个窗体级变量
dim x1 as double, x2 as double
dim OperateID as integer
窗体装载时给初值
Private Sub Form1_Load()
x1 = 0
x2 = 0
OperateID = 0
End Sub
C按钮,即清零按钮
Private Sub Button6_Click()
x1 = 0
x2 = 0
OperateID = 0
Text1.Text = 0
End Sub
+按钮
Private Sub Button1_Click()
Calculate()
x1 = Val(Text1.Text)
OperateID = 1
End Sub
-按钮
Private Sub Button2_Click()
Calculate()
x1 = Val(Text1.Text)
OperateID = 2
End Sub
*按钮
Private Sub Button3_Click()
Calculate()
x1 = Val(Text1.Text)
OperateID = 3
End Sub
/按钮
Private Sub Button4_Click()
Calculate()
x1 = Val(Text1.Text)
OperateID = 4
End Sub
=按钮
Private Sub Button5_Click()
Calculate()
End Sub
计算用的函数
Sub Calculate()
x2 = Val(Text1.Text)
Select Case OperateID
Case 1
TextBox1.Text = x1 + x2
Case 2
TextBox1.Text = x1 - x2
Case 3
TextBox1.Text = x1 * x2
Case 4
TextBox1.Text = x1 / x2
End Select
OperateID = 0
End Sub
定义几个窗体级变量
dim x1 as double, x2 as double
dim OperateID as integer
窗体装载时给初值
Private Sub Form1_Load()
x1 = 0
x2 = 0
OperateID = 0
End Sub
C按钮,即清零按钮
Private Sub Button6_Click()
x1 = 0
x2 = 0
OperateID = 0
Text1.Text = 0
End Sub
+按钮
Private Sub Button1_Click()
Calculate()
x1 = Val(Text1.Text)
OperateID = 1
End Sub
-按钮
Private Sub Button2_Click()
Calculate()
x1 = Val(Text1.Text)
OperateID = 2
End Sub
*按钮
Private Sub Button3_Click()
Calculate()
x1 = Val(Text1.Text)
OperateID = 3
End Sub
/按钮
Private Sub Button4_Click()
Calculate()
x1 = Val(Text1.Text)
OperateID = 4
End Sub
=按钮
Private Sub Button5_Click()
Calculate()
End Sub
计算用的函数
Sub Calculate()
x2 = Val(Text1.Text)
Select Case OperateID
Case 1
TextBox1.Text = x1 + x2
Case 2
TextBox1.Text = x1 - x2
Case 3
TextBox1.Text = x1 * x2
Case 4
TextBox1.Text = x1 / x2
End Select
OperateID = 0
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询