一个VB问题哦……不知道哪里错了。。在线等哈

来源:百度知道 编辑:UC知道 时间:2024/06/05 23:52:27
Public Function area(x!, y!, z!) As Single
Dim c!
c = 1 / 2 * (x + y + z)
area = Sqr(c * (c - x) * (c - y) * (c - z))
End Function

Private Sub Command1_Click()
Dim a, b, c, d, e As Single
a = InputBox("请输入a边边长")
b = InputBox("请输入b边边长")
c = InputBox("请输入c边边长")
d = InputBox("请输入d边边长")
e = InputBox("请输入e边边长")
s = area(a, b, c) + area(c, d, e)
Text1.Text = s
End Sub

Dim a, b, c, d, e As Single 应该写成
Dim a As Single, b As Single, c As Single, d As Single, e As Single。
你那种写法没定义abcd数据类型。
或Public Function area(x!, y!, z!) As Single
改成:
Public Function area(ByVal x!, ByVal y!, ByVal z!) As Single
也不会报错。

Dim a, b, c, d, e As Single 改为Dim a!, b!, c!, d!, e!
就是说传入的参数类型一定要和函数中接收的参数完全一致。

Dim a, b, c, d, e As Single 这句中除了e被定义为Single外,其他都是Variant,应该Dim a!,b!,c!,d!,e!