weixin_44213816
罒 灬
2019-01-18 11:58

vba中,按照书上用(if then...else)编了一个小程序,为什么返回不了正确值?

  • microsoft
  • Sub 判别构成三角形() '该程序有错误,无法返回正确值
  • Dim a As Double, b As Double, c As Double
  • Dim area As Double, s As Double
  • Dim flagu As Boolean, flagl As Boolean
  • a = CDbl(InputBox("请输入三角形的第1条边", "求三角形面积", 0))
  • b = CDbl(InputBox("请输入三角形的第2条边", "求三角形面积", 0))
  • c = CDbl(InputBox("请输入三角形的第3条边", "求三角形面积", 0))
  • flagu = ((a + b) > c) And ((a + c) > b) And ((b + c) > a)
  • flagl = ((a - b) < c) And ((a - c) < b) And ((b - c) < a)
  • If (falgu And flagl) Then
  • s = (a + b + c) / 2
  • area = Math.Sqr(s * (s - a) * (s - b) * (s - c))
  • MsgBox "三角形的三边分别为:a=" & a & ",b=" & b & ",c=" & c & "。面积area=" & area, vbOKOnly, "求三角形的面积"
  • Else
  • MsgBox "边长:a=" & a & ",b=" & b & ",c=" & c & "。不能构成三角形", vbOKOnly, "判断三条边是否可构成三角形"
  • End If
  • End Sub
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答