求一个简单的vb小程序 80
功能是能计算各种图形的面积……包括圆形、正方形、三角形、梯形等基本图形就是那种先选一种图形,然后输入数据,能自动算出面积的给代码和发邮箱都可以…………906741652@...
功能是能计算各种图形的面积……
包括圆形、正方形、三角形、梯形等基本图形
就是那种先选一种图形,然后输入数据,能自动算出面积的
给代码和发邮箱都可以…………
906741652@qq.com 展开
包括圆形、正方形、三角形、梯形等基本图形
就是那种先选一种图形,然后输入数据,能自动算出面积的
给代码和发邮箱都可以…………
906741652@qq.com 展开
2个回答
展开全部
VERSION 5.00
Begin VB.Form FormMj
Caption = "求各种图形面积"
ClientHeight = 3135
ClientLeft = 60
ClientTop = 345
ClientWidth = 4905
LinkTopic = "FormMj"
ScaleHeight = 3135
ScaleWidth = 4905
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton sanjx1_btn
Caption = "三角形1"
Height = 375
Left = 1200
TabIndex = 3
Top = 720
Width = 1095
End
Begin VB.CommandButton tiXing1
Caption = "梯形面积"
Height = 375
Left = 3720
TabIndex = 2
Top = 720
Width = 975
End
Begin VB.CommandButton sanbx2_btn
Caption = "三角形2"
Height = 375
Left = 2520
TabIndex = 1
Top = 720
Width = 975
End
Begin VB.CommandButton Command1
Caption = "圆面积"
Height = 375
Left = 120
TabIndex = 0
Top = 720
Width = 855
End
End
Attribute VB_Name = "FormMj"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const PI = 3.1415926
Private Sub Command1_Click() '求圆的面积()
Dim R!
R = Val(InputBox("请输入半径!"))
''使用print方法在窗体上打印圆的周长和面积
Print "半径为" & R & "的圆:"
Print "周长为" & 2 * PI * R
Print "面积为" & PI * R * R
End Sub
Function S_yuan(R As Single) As Single '求圆的面积(函数)
S_yuan = PI * R ^ 2
End Function
Function V_yuan(R As Single) As Single '计算圆球的体积
V_yuan = 4 * PI * R ^ 3 / 3
End Function
Private Sub sanjx1_btn_Click() '求三角形面积1(底*高/2)
Dim x, h, S As Double
On Error Resume Next
x = CDbl(InputBox("输入三角形 底边"))
h = CDbl(InputBox("输入三角形 高"))
If (x <= 0) Then x = CDbl(InputBox("有误,请再次输入 底边"))
If (h <= 0) Then h = CDbl(InputBox("有误,请再次输入 高"))
If (x > 0 And h > 0) Then
S = (x * h) / 2
MsgBox "三角形的面积为" & S
Else
MsgBox " !" & vbCrLf & "无法计算三角形面积x=" & x & ",h=" & h
End If
End Sub
Private Sub sanbx2_btn_Click() '求三角形面积2(三边)
Dim x, y, z, S As Double
Do
x = CDbl(InputBox("输入第一边"))
y = CDbl(InputBox("输入第二边"))
z = CDbl(InputBox("输入第三边"))
Loop Until x + y > z And x + z > y And y + z > x
S = (x + y + z) / 2
MsgBox "三角形面积为" & Sqr(S * (S - x) * (S - y) * (S - z))
End Sub
Private Sub tiXing1_Click() ' '求梯形面积(一)
Dim x, y, z, S As Double
Do
x = CDbl(InputBox("请输入梯形上底"))
y = CDbl(InputBox("请输入梯形下底"))
h = CDbl(InputBox("请输入梯形的高"))
Loop Until x > 0 And y > 0 And h > 0
MsgBox "梯形面积为" & (x + y) * h / 2
End Sub
Private Sub tiXing2_Click() '求梯形面积(二)
a = Text1.Text
b = Text2.Text
h = Text3.Text
S = (Val(a) + Val(b)) * Val(h) / 2
Text4.Text = Format(S, "0.00") ''结果保留2位,存入文本框中
End Sub
''''''其它图形可依次添加!''''''
''将上面的代码复制下来,粘贴到记事本里,'另保存为"vb求各种面积.frm"(保存类型:所有文件)用VB6打开,运行即可。
Begin VB.Form FormMj
Caption = "求各种图形面积"
ClientHeight = 3135
ClientLeft = 60
ClientTop = 345
ClientWidth = 4905
LinkTopic = "FormMj"
ScaleHeight = 3135
ScaleWidth = 4905
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton sanjx1_btn
Caption = "三角形1"
Height = 375
Left = 1200
TabIndex = 3
Top = 720
Width = 1095
End
Begin VB.CommandButton tiXing1
Caption = "梯形面积"
Height = 375
Left = 3720
TabIndex = 2
Top = 720
Width = 975
End
Begin VB.CommandButton sanbx2_btn
Caption = "三角形2"
Height = 375
Left = 2520
TabIndex = 1
Top = 720
Width = 975
End
Begin VB.CommandButton Command1
Caption = "圆面积"
Height = 375
Left = 120
TabIndex = 0
Top = 720
Width = 855
End
End
Attribute VB_Name = "FormMj"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const PI = 3.1415926
Private Sub Command1_Click() '求圆的面积()
Dim R!
R = Val(InputBox("请输入半径!"))
''使用print方法在窗体上打印圆的周长和面积
Print "半径为" & R & "的圆:"
Print "周长为" & 2 * PI * R
Print "面积为" & PI * R * R
End Sub
Function S_yuan(R As Single) As Single '求圆的面积(函数)
S_yuan = PI * R ^ 2
End Function
Function V_yuan(R As Single) As Single '计算圆球的体积
V_yuan = 4 * PI * R ^ 3 / 3
End Function
Private Sub sanjx1_btn_Click() '求三角形面积1(底*高/2)
Dim x, h, S As Double
On Error Resume Next
x = CDbl(InputBox("输入三角形 底边"))
h = CDbl(InputBox("输入三角形 高"))
If (x <= 0) Then x = CDbl(InputBox("有误,请再次输入 底边"))
If (h <= 0) Then h = CDbl(InputBox("有误,请再次输入 高"))
If (x > 0 And h > 0) Then
S = (x * h) / 2
MsgBox "三角形的面积为" & S
Else
MsgBox " !" & vbCrLf & "无法计算三角形面积x=" & x & ",h=" & h
End If
End Sub
Private Sub sanbx2_btn_Click() '求三角形面积2(三边)
Dim x, y, z, S As Double
Do
x = CDbl(InputBox("输入第一边"))
y = CDbl(InputBox("输入第二边"))
z = CDbl(InputBox("输入第三边"))
Loop Until x + y > z And x + z > y And y + z > x
S = (x + y + z) / 2
MsgBox "三角形面积为" & Sqr(S * (S - x) * (S - y) * (S - z))
End Sub
Private Sub tiXing1_Click() ' '求梯形面积(一)
Dim x, y, z, S As Double
Do
x = CDbl(InputBox("请输入梯形上底"))
y = CDbl(InputBox("请输入梯形下底"))
h = CDbl(InputBox("请输入梯形的高"))
Loop Until x > 0 And y > 0 And h > 0
MsgBox "梯形面积为" & (x + y) * h / 2
End Sub
Private Sub tiXing2_Click() '求梯形面积(二)
a = Text1.Text
b = Text2.Text
h = Text3.Text
S = (Val(a) + Val(b)) * Val(h) / 2
Text4.Text = Format(S, "0.00") ''结果保留2位,存入文本框中
End Sub
''''''其它图形可依次添加!''''''
''将上面的代码复制下来,粘贴到记事本里,'另保存为"vb求各种面积.frm"(保存类型:所有文件)用VB6打开,运行即可。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'个人编写仅供参考,将下面的代码复制下来,保存为Form1.frm用VB6打开,运行即可。
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 7050
ClientLeft = 60
ClientTop = 450
ClientWidth = 10650
LinkTopic = "Form1"
ScaleHeight = 7050
ScaleWidth = 10650
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame2
Caption = "参数"
Height = 3855
Left = 2760
TabIndex = 9
Top = 1440
Width = 6615
Begin VB.TextBox Text1
Height = 495
Index = 0
Left = 3960
TabIndex = 13
Text = "Text1"
Top = 360
Width = 2415
End
Begin VB.TextBox Text1
Height = 495
Index = 1
Left = 3960
TabIndex = 12
Text = "Text1"
Top = 960
Width = 2415
End
Begin VB.TextBox Text1
Height = 495
Index = 2
Left = 3960
TabIndex = 11
Text = "Text1"
Top = 1560
Width = 2415
End
Begin VB.TextBox Text1
Height = 495
Index = 3
Left = 3960
TabIndex = 10
Text = "Text1"
Top = 2880
Width = 2415
End
Begin VB.Label Label1
Caption = "圆半径 正方形边长 长方形长 三角形底边 梯形上底边 平行四边形底"
Height = 495
Left = 240
TabIndex = 17
Top = 360
Width = 3615
End
Begin VB.Label Label2
Caption = "长方形宽 三角形高 梯形高 平行四边形高"
Height = 375
Left = 240
TabIndex = 16
Top = 960
Width = 3495
End
Begin VB.Label Label3
Caption = "梯形下底边"
Height = 375
Left = 240
TabIndex = 15
Top = 1560
Width = 3615
End
Begin VB.Label Label4
Caption = "计算结果 "
Height = 255
Left = 240
TabIndex = 14
Top = 3000
Width = 3495
End
End
Begin VB.TextBox Text2
Height = 375
Left = 11160
TabIndex = 8
Text = "Text2"
Top = 5760
Width = 2055
End
Begin VB.Frame Frame1
Caption = "多边形"
Height = 3855
Left = 840
TabIndex = 1
Top = 1440
Width = 1815
Begin VB.OptionButton Option1
Caption = "平行四边形"
Height = 255
Index = 5
Left = 240
TabIndex = 7
Top = 3000
Width = 1335
End
Begin VB.OptionButton Option1
Caption = "三角形"
Height = 255
Index = 4
Left = 240
TabIndex = 6
Top = 2040
Width = 1335
End
Begin VB.OptionButton Option1
Caption = "梯形"
Height = 255
Index = 3
Left = 240
TabIndex = 5
Top = 2520
Width = 1335
End
Begin VB.OptionButton Option1
Caption = "长方形"
Height = 255
Index = 2
Left = 240
TabIndex = 4
Top = 1560
Width = 1335
End
Begin VB.OptionButton Option1
Caption = "正方形"
Height = 255
Index = 1
Left = 240
TabIndex = 3
Top = 1080
Width = 1335
End
Begin VB.OptionButton Option1
Caption = "圆"
Height = 255
Index = 0
Left = 240
TabIndex = 2
Top = 600
Width = 1335
End
End
Begin VB.CommandButton Command1
Caption = "计算"
Height = 495
Left = 3840
TabIndex = 0
Top = 720
Width = 1695
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim XingZh As Integer
Private Sub Command1_Click()
Dim A, B, C
On Error Resume Next
A = Val(Text1(0).Text)
B = Val(Text1(1).Text)
C = Val(Text1(2).Text)
Select Case XingZh
Case 0
Text1(3).Text = 3.14159 * A * A
Case 1
Text1(3).Text = A * A
Case 2
Text1(3).Text = A * B
Case 3
Text1(3).Text = A * B / 2
Case 4
Text1(3).Text = (A + C) * B / 2
Case 5
Text1(3).Text = A * B
Case Else
End Select
End Sub
Private Sub Form_Load()
Option1(0).Value = True
XingZh = 0
For ii = 0 To 3
Text1(ii).Text = 0
Next ii
End Sub
Private Sub Option1_Click(Index As Integer)
XingZh = Index
Text2.Text = XingZh
End Sub
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 7050
ClientLeft = 60
ClientTop = 450
ClientWidth = 10650
LinkTopic = "Form1"
ScaleHeight = 7050
ScaleWidth = 10650
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame2
Caption = "参数"
Height = 3855
Left = 2760
TabIndex = 9
Top = 1440
Width = 6615
Begin VB.TextBox Text1
Height = 495
Index = 0
Left = 3960
TabIndex = 13
Text = "Text1"
Top = 360
Width = 2415
End
Begin VB.TextBox Text1
Height = 495
Index = 1
Left = 3960
TabIndex = 12
Text = "Text1"
Top = 960
Width = 2415
End
Begin VB.TextBox Text1
Height = 495
Index = 2
Left = 3960
TabIndex = 11
Text = "Text1"
Top = 1560
Width = 2415
End
Begin VB.TextBox Text1
Height = 495
Index = 3
Left = 3960
TabIndex = 10
Text = "Text1"
Top = 2880
Width = 2415
End
Begin VB.Label Label1
Caption = "圆半径 正方形边长 长方形长 三角形底边 梯形上底边 平行四边形底"
Height = 495
Left = 240
TabIndex = 17
Top = 360
Width = 3615
End
Begin VB.Label Label2
Caption = "长方形宽 三角形高 梯形高 平行四边形高"
Height = 375
Left = 240
TabIndex = 16
Top = 960
Width = 3495
End
Begin VB.Label Label3
Caption = "梯形下底边"
Height = 375
Left = 240
TabIndex = 15
Top = 1560
Width = 3615
End
Begin VB.Label Label4
Caption = "计算结果 "
Height = 255
Left = 240
TabIndex = 14
Top = 3000
Width = 3495
End
End
Begin VB.TextBox Text2
Height = 375
Left = 11160
TabIndex = 8
Text = "Text2"
Top = 5760
Width = 2055
End
Begin VB.Frame Frame1
Caption = "多边形"
Height = 3855
Left = 840
TabIndex = 1
Top = 1440
Width = 1815
Begin VB.OptionButton Option1
Caption = "平行四边形"
Height = 255
Index = 5
Left = 240
TabIndex = 7
Top = 3000
Width = 1335
End
Begin VB.OptionButton Option1
Caption = "三角形"
Height = 255
Index = 4
Left = 240
TabIndex = 6
Top = 2040
Width = 1335
End
Begin VB.OptionButton Option1
Caption = "梯形"
Height = 255
Index = 3
Left = 240
TabIndex = 5
Top = 2520
Width = 1335
End
Begin VB.OptionButton Option1
Caption = "长方形"
Height = 255
Index = 2
Left = 240
TabIndex = 4
Top = 1560
Width = 1335
End
Begin VB.OptionButton Option1
Caption = "正方形"
Height = 255
Index = 1
Left = 240
TabIndex = 3
Top = 1080
Width = 1335
End
Begin VB.OptionButton Option1
Caption = "圆"
Height = 255
Index = 0
Left = 240
TabIndex = 2
Top = 600
Width = 1335
End
End
Begin VB.CommandButton Command1
Caption = "计算"
Height = 495
Left = 3840
TabIndex = 0
Top = 720
Width = 1695
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim XingZh As Integer
Private Sub Command1_Click()
Dim A, B, C
On Error Resume Next
A = Val(Text1(0).Text)
B = Val(Text1(1).Text)
C = Val(Text1(2).Text)
Select Case XingZh
Case 0
Text1(3).Text = 3.14159 * A * A
Case 1
Text1(3).Text = A * A
Case 2
Text1(3).Text = A * B
Case 3
Text1(3).Text = A * B / 2
Case 4
Text1(3).Text = (A + C) * B / 2
Case 5
Text1(3).Text = A * B
Case Else
End Select
End Sub
Private Sub Form_Load()
Option1(0).Value = True
XingZh = 0
For ii = 0 To 3
Text1(ii).Text = 0
Next ii
End Sub
Private Sub Option1_Click(Index As Integer)
XingZh = Index
Text2.Text = XingZh
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询