狂晕。冤死了,括号括错位置了,白丢了分: Private Sub CommandButton1_Click() Dim i As Integer For i = ActiveSheet.Shapes.Count To 1 Step -1 If ActiveSheet.Shapes(i).Type = 9 Then ActiveSheet.Shapes(i).Delete Next End Sub Private Sub CommandButton2_Click() Dim i As Integer, arr, p As Single, s As Single arr = Range("a3:b14") For i = 2 To 12 ActiveSheet.Shapes.AddLine arr(i, 1) / 4, arr(i, 2) / 4, arr(i - 1, 1) / 4, arr(i - 1, 2) / 4 s = s + (arr(i, 1) - arr(i - 1, 1)) * (arr(i, 2) + arr(i - 1, 2)) / 2 p = p + Sqr((arr(i, 1) - arr(i - 1, 1)) ^ 2 + (arr(i, 2) - arr(i - 1, 2)) ^ 2) Next MsgBox "该多边形的面积为:" & s & vbCrLf & vbCrLf & "周长为:" & p Application.StatusBar = "该多边形的面积为:" & s & vbCrLf & vbCrLf & "周长为:" & p End Sub
|