求解2道vb题答案

2024-12-03 00:55:26
推荐回答(2个)
回答1:

第一题:你要在窗体放一个label按钮.

Private Sub Form_Click()

Dim a As Integer

Dim b As Integer

Dim c As Integer

Dim d As Double

Dim s As Double

 a = InputBox("请输入第一条边", "输入", 3)

 b = InputBox("请输入第二条边", "输入", 3)

 c = InputBox("请输入第三条边", "输入", 3)

 If a + b > c And a + c > b And b + c > a Then

 d = (a + b + c) / 2

 s = Sqr(d * (d - a) * (d - b) * (d - c))

  Label1.Caption = "三角形的面积是" & s & "三角形周长是" & a + b + c

   Else

   MsgBox "不能构成三角形"

End If

  第二题:做三个label,一个cammand

Private Sub command1_Click()

Dim a As Integer

Dim b As Integer

Dim c As Integer

a = InputBox("请输入第一个数", "输入", 5)

b = InputBox("请输入第二个数", "输入", 8)

c = InputBox("请办入第三个数", "输入", 3)

Label1.Caption = a

Label2.Caption = b

Label3.Caption = c

If a < b And b < c Then

     

     Print "三个数从小到大排"; a; b; c

  ElseIf a < b And c > b Then

  Print "三个数从小到大排"; a; c; b

 ElseIf b < a And a < c Then

 

     Print "三个数从小到大排"; b; a; c

  ElseIf b < a And c > a Then

  Print "三个数从小到大排"; b; c; a

  

 ElseIf c < a And a < b Then

      Print "三个数从小到大排"; c; a; b

      Else

      Print "三个数从小到大排"; c; b; a

End If

End Sub

回答2:

1
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim a, b, c, tempd As Double
a = InputBox("请输入a", "", 0)
b = InputBox("请输入b", "", 0)
c = InputBox("请输入c", "", 0)
If a < b Then
tempd = a
a = b
b = tempd
End If
If a < c Then
tempd = a
a = c
c = tempd
End If
If a * a = b * b + c * c Then
Label1.Caption = a * a & "=" & b * b & "+" & c * c
Else
MsgBox ("不能构成三角形")
End If
End Sub

2
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim a, b, c As Double
a = InputBox("请输入a", "", 5)
b = InputBox("请输入b", "", 8)
c = InputBox("请输入c", "", 3)
Label1.Caption = Val(a)
Label2.Caption = Val(b)
Label3.Caption = Val(c)
End Sub
Private Sub Command1_Click()
Dim a, b, c, tempd As Double
a = Val(Label1.Caption)
b = Val(Label2.Caption)
c = Val(Label3.Caption)
If a < b Then
tempd = a
a = b
b = tempd
End If
If a < c Then
tempd = a
a = c
c = tempd
End If
If b < c Then
tempd = b
b = c
c = tempd
End If
Print "三个数从小到大为:" & c & "," & b & "," & a
End Sub