vb.net求面积 vb中计算三角形面积的代码( 二 )


5.vb .net 已经成为完全的面向对象的编程语言,并且新增更多语言特性 。
参考资料:百度百科:VB
谁知道怎么用VB.NET编写一个算长方形面积的程序?dim a as single=...'自己输入长方形vb.net求面积的长
dim b as single=...'自己输入长方形vb.net求面积的宽
dim c as single=a*b'计算面积
textbox1.text=c'显示面积
vb.net任意n边形面积Private Type PointXY
x As Double
y As Double
End Type
Private Sub Command1_Click()
Dim n As Integer
Dim s As Double
Dim sum As Double
Dim a() As PointXY
n = InputBox("请输入多边形的边数")
ReDim a(n)
s = 0
sum = 0
For i = 1 To n
a(i).x = Val(InputBox("请输入第"i"个点的坐标的X值"))
a(i).y = Val(InputBox("请输入第"i"个点的坐标的Y值"))
Next i
For i = 1 To n - 1
sum = sum + (a(i).x * a(i + 1).y - a(i + 1).x * a(i).y)
Next i
sum = sum + a(n).x * a(1).y - a(1).x * a(n).y
s = 0.5 * sum
MsgBox ("该多边形的面积为 "Abs(s))
End Sub
Private Sub Command2_Click()
Dim n As Integer
Dim sum As Double
Dim a() As PointXY
n = InputBox("请输入多边形的边数")
ReDim a(n)
s = 0
sum = 0
For i = 1 To n
a(i).x = Val(InputBox("请输入第"i"个点的坐标的X值"))
a(i).y = Val(InputBox("请输入第"i"个点的坐标的Y值"))
Next i
For i = 1 To n - 1
sum = sum + Sqr((a(i).x - a(i + 1).x) ^ 2 - (a(i).y - a(i + 1).y) ^ 2)
Next i
sum = sum + Sqr((a(n).x - a(1).x) ^ 2 - (a(n).y - a(1).y) ^ 2)
MsgBox ("该多边形的周长为 "sum)
End Sub
【vb.net求面积 vb中计算三角形面积的代码】vb.net求面积的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于vb中计算三角形面积的代码、vb.net求面积的信息别忘了在本站进行查找喔 。

推荐阅读