vba中的函数定义Sub 已知三边求三角()a = InputBox("a边")b = InputBox("b边")c = InputBox("c边")If Max(a,b,c) - Min(a,b,c) < a + b + c - Max(a,b,c) - Min(a,b,c) Thenx = Acos((b ^ 2 + c ^ 2 - a ^ 2) / (2 * b * c))y = Acos((a ^ 2 + c ^ 2 -
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/25 17:56:46
vba中的函数定义Sub 已知三边求三角()a = InputBox("a边")b = InputBox("b边")c = InputBox("c边")If Max(a,b,c) - Min(a,b,c) < a + b + c - Max(a,b,c) - Min(a,b,c) Thenx = Acos((b ^ 2 + c ^ 2 - a ^ 2) / (2 * b * c))y = Acos((a ^ 2 + c ^ 2 -
vba中的函数定义
Sub 已知三边求三角()
a = InputBox("a边")
b = InputBox("b边")
c = InputBox("c边")
If Max(a,b,c) - Min(a,b,c) < a + b + c - Max(a,b,c) - Min(a,b,c) Then
x = Acos((b ^ 2 + c ^ 2 - a ^ 2) / (2 * b * c))
y = Acos((a ^ 2 + c ^ 2 - b ^ 2) / (2 * a * c))
z = Acos((b ^ 2 + a ^ 2 - c ^ 2) / (2 * b * a))
MsgBox "A=" & x
MsgBox "B=" & y
MsgBox "C=" & z
Else
MsgBox "此三边不可围成三角形"
End If
End Sub
输入后按f5,显示
编译错误:
子过程或函数未定义
”Max“被覆上光标
上为在excel2003中的vba编辑器中的出现的问题.
我是初学者.
vba中的函数定义Sub 已知三边求三角()a = InputBox("a边")b = InputBox("b边")c = InputBox("c边")If Max(a,b,c) - Min(a,b,c) < a + b + c - Max(a,b,c) - Min(a,b,c) Thenx = Acos((b ^ 2 + c ^ 2 - a ^ 2) / (2 * b * c))y = Acos((a ^ 2 + c ^ 2 -
你这哪里是写程序.
你的程序没有写完,在VB中Max,Min,Acos等等都需要自己写代码.
完整程序如下:(注意:你的算法我没有改,但我认为有问题,你自己对付吧)
Sub 已知三边求三角()
a = InputBox("a边")
b = InputBox("b边")
c = InputBox("c边")
If Max(CDbl(a),CDbl(b),CDbl(c)) - Min(CDbl(a),CDbl(b),CDbl(c)) < a + b + c - Max(CDbl(a),CDbl(b),CDbl(c)) - Min(CDbl(a),CDbl(b),CDbl(c)) Then
x = ACos((b ^ 2 + c ^ 2 - a ^ 2) / (2 * b * c))
y = ACos((a ^ 2 + c ^ 2 - b ^ 2) / (2 * a * c))
z = ACos((b ^ 2 + a ^ 2 - c ^ 2) / (2 * b * a))
MsgBox "A=" & x
MsgBox "B=" & y
MsgBox "C=" & z
Else
MsgBox "此三边不可围成三角形"
End If
End Sub
Function Max(a As Double,b As Double,c As Double) As Double
Dim Ai(3) As Double
Ai(1) = a:Ai(1) = b:Ai(1) = c
For I = 1 To 3
If Ai(I) > Max Then
Max = Ai(I)
End If
Next
End Function
Function Min(a As Double,b As Double,c As Double) As Double
Dim Ai(3) As Double
Ai(1) = a:Ai(1) = b:Ai(1) = c
For I = 1 To 3
If Ai(I) < Min Then
Min = Ai(I)
End If
Next
End Function
Function ACos(x As Double) As Double
If x >= -1 And x < -0.5 Then ACos = Atn(Sqr(1 - x * x) / x) + 4 * Atn(1)
If x >= -0.5 And x 0.5 And x