精选问答
用VB编一个计算器要求:1、十进制数的加、减、乘、除、乘方、取模等简单计算2、科学计算函数,包括(反)正弦、(反)余弦、(反)正切、(反)余切、开方、指数等函数运行3、以角度、弧度两种方式实现上述部分函数4、具备历史计算的记忆功能5、对不正确的表达式能指出其错误原因6、整理上机步骤、完成实验报告、提交可运行的程序,给出实验数据和实验结果。

2019-05-23

用VB编一个计算器
要求:
1、十进制数的加、减、乘、除、乘方、取模等简单计算
2、科学计算函数,包括(反)正弦、(反)余弦、(反)正切、(反)余切、开方、指数等函数运行
3、以角度、弧度两种方式实现上述部分函数
4、具备历史计算的记忆功能
5、对不正确的表达式能指出其错误原因
6、整理上机步骤、完成实验报告、提交可运行的程序,给出实验数据和实验结果。
优质解答
给我你的邮箱,我把工程发过去
代码
Dim pi As Double
Dim temp As Double
Dim j As Integer
Dim te As String
Dim yf As String
Dim m As Boolean
Dim f As Boolean
Private Sub Command1_Click(Index As Integer)
If f = True Then Text1 = ""
If Index = 10 Then
Text1.Text = Text1.Text & "."
Else
Text1.Text = Text1.Text & Index
End If
f = False
End Sub
Private Sub Command2_Click(Index As Integer)
Call kl
temp = Text1
Text1 = ""
Text1 = Command2(Index).Caption
f = True
yf = Command2(Index).Caption
End Sub
Private Sub Command3_Click()
If m = True Then
Call kl
Else
Select Case yf
Case "+"
Text1 = temp + Val(Text1)
Case "-"
Text1 = temp - Val(Text1)
Case "*"
Text1 = temp * Val(Text1)
Case "/"
If Val(Text1) = 0 Then
MsgBox "除数不为0"
Else
Text1 = temp / Val(Text1)
End If
End Select
End If
End Sub
Sub kl()
If m = True Then
a = Val(Replace(Text1, te, ""))
If te = "sin" Then
If Option1.Value = True Then
Text1 = Sin(a * pi / 180)
Else
a = Val(Replace(Text1, "π/", ""))
Text1 = Sin(pi / a)
End If
ElseIf te = "sprt" Then
Text1 = Sqr(a)
ElseIf te = "1/x" Then
Text1 = 1 / a
ElseIf te = "%" Then
Text1 = a * 100
ElseIf te = "cos" Then
If Option1.Value = True Then
Text1 = Cos(a * pi / 180)
Else
a = Val(Replace(Text1, "π/", ""))
Text1 = Cos(pi / a)
End If
ElseIf te = "tan" Then
If Option1.Value = True Then
Text1 = Tan(a * pi / 180)
Else
a = Val(Replace(Text1, "π/", ""))
Text1 = Tan(pi / a)
End If
ElseIf te = "ln" Then '等号的ln计算
Text1 = Log(Val(Text1.Text))
End If
m = False
End If
End Sub
Private Sub Command4_Click()
Text1.Text = Mid(Text1, 1, Len(Text1.Text) - 1)
End Sub
Private Sub Command5_Click()
Text1.Text = ""
temp = 0
m = False
End Sub
Private Sub Command6_Click(Index As Integer)
Text1.Text = Command6(Index).Caption
te = Command6(Index).Caption
m = True
End Sub
Private Sub Command7_Click()
End
End Sub
Private Sub Command8_Click()
Text1 = "π/"
End Sub
Private Sub Form_Load()
pi = 4 * Atn(1)
End Sub
给我你的邮箱,我把工程发过去
代码
Dim pi As Double
Dim temp As Double
Dim j As Integer
Dim te As String
Dim yf As String
Dim m As Boolean
Dim f As Boolean
Private Sub Command1_Click(Index As Integer)
If f = True Then Text1 = ""
If Index = 10 Then
Text1.Text = Text1.Text & "."
Else
Text1.Text = Text1.Text & Index
End If
f = False
End Sub
Private Sub Command2_Click(Index As Integer)
Call kl
temp = Text1
Text1 = ""
Text1 = Command2(Index).Caption
f = True
yf = Command2(Index).Caption
End Sub
Private Sub Command3_Click()
If m = True Then
Call kl
Else
Select Case yf
Case "+"
Text1 = temp + Val(Text1)
Case "-"
Text1 = temp - Val(Text1)
Case "*"
Text1 = temp * Val(Text1)
Case "/"
If Val(Text1) = 0 Then
MsgBox "除数不为0"
Else
Text1 = temp / Val(Text1)
End If
End Select
End If
End Sub
Sub kl()
If m = True Then
a = Val(Replace(Text1, te, ""))
If te = "sin" Then
If Option1.Value = True Then
Text1 = Sin(a * pi / 180)
Else
a = Val(Replace(Text1, "π/", ""))
Text1 = Sin(pi / a)
End If
ElseIf te = "sprt" Then
Text1 = Sqr(a)
ElseIf te = "1/x" Then
Text1 = 1 / a
ElseIf te = "%" Then
Text1 = a * 100
ElseIf te = "cos" Then
If Option1.Value = True Then
Text1 = Cos(a * pi / 180)
Else
a = Val(Replace(Text1, "π/", ""))
Text1 = Cos(pi / a)
End If
ElseIf te = "tan" Then
If Option1.Value = True Then
Text1 = Tan(a * pi / 180)
Else
a = Val(Replace(Text1, "π/", ""))
Text1 = Tan(pi / a)
End If
ElseIf te = "ln" Then '等号的ln计算
Text1 = Log(Val(Text1.Text))
End If
m = False
End If
End Sub
Private Sub Command4_Click()
Text1.Text = Mid(Text1, 1, Len(Text1.Text) - 1)
End Sub
Private Sub Command5_Click()
Text1.Text = ""
temp = 0
m = False
End Sub
Private Sub Command6_Click(Index As Integer)
Text1.Text = Command6(Index).Caption
te = Command6(Index).Caption
m = True
End Sub
Private Sub Command7_Click()
End
End Sub
Private Sub Command8_Click()
Text1 = "π/"
End Sub
Private Sub Form_Load()
pi = 4 * Atn(1)
End Sub
相关问答