VB计算圆周长,麻烦帮我看看哪错了?

来源:百度知道 编辑:UC知道 时间:2024/05/12 09:34:35
用Textbox控件输入半径,计算圆的周长和面积。
进一步要求,为了保证程序的运行正确,对输入的半径的要进行合法性检查,若发现有非法的数据输入,利用msgbox显示出错信息。

提示:主要是MsgBox函数的应用,它用于向用户发布提示信息,要求用户作出必要的反应。其格式: MsgBox(msg[,type][,title][,helpfile,context])

我这样写的:Dim r As Single, c As Single, s As Single, pi As Single
pi = 3.1415926
r = Val(Text1.Text)
If r >= 10 And r <= 60 Then
c = 2 * pi * r
s = pi * r * r
Text2.Text = c
Text3.Text = s
Else
MsgBox msg([,对不起,数据错误])
End If

http://www.yesky.com/imagesnew/software/vbscript/html/vsfctMsgBox.htm

下面的例子演示了 MsgBox 函数的用法:

Dim MyVar
MyVar = MsgBox ("Hello World!", 65, "MsgBox Example")
' MyVar contains either 1 or 2, depending on which button is clicked.

[]是可选的意思