制作一个简易VB计算器(可以连加,连减)
这是我做的(由于字数限制只能发部分我做的),只能实现简单的单步运算现在老师说要我们在text上显示(5+6+9+5......=这样同级运算的连加连减。)希望各位给个提示...
这是我做的(由于字数限制只能发部分我做的),只能实现简单的单步运算
现在老师说要我们在text上显示(5+6+9+5......=这样同级运算的连加连减。)
希望各位给个提示,指点我需要在哪个地方修改,添加
Dim OperatorState As Integer
Dim Data1 As Integer
Dim result As Integer
Dim Data2 As Integer
Private Sub Command1_Click()
Text1.Text = Text1.Text + "7"
End Sub
Private Sub Command10_Click()
Text1.Text = Text1.Text + "6"
End Sub
Private Sub Command11_Click()
Text1.Text = Text1.Text + "3"
End Sub
Private Sub Command12_Click()
Data1 = Val(Text1.Text)
OperatorState = 3
Text1.Text = ""
End Sub
Private Sub Command13_Click()
Text1.Text = ""
End Sub
Private Sub Command14_Click()
Data2 = Val(Text1.Text)
If (OperatorState = 1) Then
result = Data1 + Data2
End If
If (OperatorState = 2) Then
result = Data1 - Data2
End If
If (OperatorState = 3) Then
result = Data1 * Data2
End If
If (OperatorState = 4) Then
result = Data1 / Data2
End If
Text1.Text = Str(result)
End Sub
Private Sub Command15_Click()
Text1.Text = Text1.Text + "0"
End Sub
Private Sub Command16_Click()
Data1 = Val(Text1.Text)
OperatorState = 4
Text1.Text = ""
End Sub
Private Sub Command2_Click()
Text1.Text = Text1.Text + "4"
End Sub
Private Sub Command3_Click()
Text1.Text = Text1.Text + "1"
End Sub
Private Sub Command4_Click()
Data1 = Val(Text1.Text)
OperatorState = 1 展开
现在老师说要我们在text上显示(5+6+9+5......=这样同级运算的连加连减。)
希望各位给个提示,指点我需要在哪个地方修改,添加
Dim OperatorState As Integer
Dim Data1 As Integer
Dim result As Integer
Dim Data2 As Integer
Private Sub Command1_Click()
Text1.Text = Text1.Text + "7"
End Sub
Private Sub Command10_Click()
Text1.Text = Text1.Text + "6"
End Sub
Private Sub Command11_Click()
Text1.Text = Text1.Text + "3"
End Sub
Private Sub Command12_Click()
Data1 = Val(Text1.Text)
OperatorState = 3
Text1.Text = ""
End Sub
Private Sub Command13_Click()
Text1.Text = ""
End Sub
Private Sub Command14_Click()
Data2 = Val(Text1.Text)
If (OperatorState = 1) Then
result = Data1 + Data2
End If
If (OperatorState = 2) Then
result = Data1 - Data2
End If
If (OperatorState = 3) Then
result = Data1 * Data2
End If
If (OperatorState = 4) Then
result = Data1 / Data2
End If
Text1.Text = Str(result)
End Sub
Private Sub Command15_Click()
Text1.Text = Text1.Text + "0"
End Sub
Private Sub Command16_Click()
Data1 = Val(Text1.Text)
OperatorState = 4
Text1.Text = ""
End Sub
Private Sub Command2_Click()
Text1.Text = Text1.Text + "4"
End Sub
Private Sub Command3_Click()
Text1.Text = Text1.Text + "1"
End Sub
Private Sub Command4_Click()
Data1 = Val(Text1.Text)
OperatorState = 1 展开
2个回答
展开全部
你的程序不全,给你个思路吧:能否考虑多加两个文本框用来放过程性结果的?比如你按5+后,一个文本框记录你的数据,另一文本框记录你的运算符,下次再按别的数字的时候就好计算了。界面上仍然显示连加或减
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'满足你的要求的吧
Private Sub Command1_Click()
Call Calc(Text1)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Call Calc(Text1)
End Sub
Sub Calc(strExpr As String)
Dim objSC As Object
On Error GoTo E_Handle
Set objSC = CreateObject("ScriptControl")
objSC.Language = "VBScript"
Text2.Text = objSC.Eval(strExpr)
E_Handle:
Set objSC = Nothing
If (Err.Number) Then
Err.Clear
Text2 = ""
MsgBox "执行过程出错。", 32
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询