展开全部
根据你追问的问题看,还是你定义数据类型匹配与不匹配的问题,m,n如果像你图片中定义显示定义成变体型,其中的赋值语句m=3.141592*(p/s)^2两侧默认都是变体型数据,所以不出错,如果定义成single,那么两侧的数据类型就不匹配了,赋值就会出错。
楼上的几个需要注意的问题,你确实应该注意的
你可以参照我写的相应代码
'定义一个面积计算过程
Sub mjjs(a As Single, b As Single, c As Single)
'定义两个变量存放面积数值、两个辅助变量和半径
Dim SN As Single, SW As Single
Dim P As Single, S As Single
Dim R1 As Single, R2 As Single
P = (a + b + c) / 2
S = Sqr(P * (P - a) * (P - b) * (P - c))
R1 = S / P
R2 = (a * b * c) / (4 * S)
'内切圆面积
SN = 3.141592 * R1 ^ 2
'外接圆面积
SW = 3.141592 * R2 ^ 2
'赋值给文本框
Text4.Text = SN
Text5.Text = SW
End Sub
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
Call mjjs(a, b, c)
End Sub
展开全部
Sub fact(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer, m As Single, n As Single)
'……此部分照搬原来的
End Sub
Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Integer
Dim m As Single, n As Single
a = Val(text1.Text)
b = Val(text2.Text)
c = Val(text3.Text)
Call fact(a, b, c, m, n)
text4.Text = m
text5.Text = n
End Sub
几个需要注意的问题
1:定义方法fact中的参数a,b,c要分别列出定义类型
2:Dim要分别定义a,b,c的类型,连续写,只有C才是integer,a和b默认是变体型
3:m,n要定义
4:text4和text5显示的是计算后的m和n,那f和t是从哪来的?
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询