一个vb的问题

想写个开立方的程序,有两个文本框:a:被开方数,b:结果,但是当输入负数时,都会出现问题,无效的过程调用或参数。以下是代码:PrivateSubok_Click()Dim... 想写个开立方的程序,有两个文本框:a:被开方数,b:结果,但是当输入负数时,都会出现问题,无效的过程调用或参数。
以下是代码:
Private Sub ok_Click()
Dim msga
If a.Text = "" Then
msga = MsgBox("请输入被开方数!", vbCritical, "无法开平方")
b.Text = "----无法计算-----"
Else
If a.Text = 0 Then
b.Text = 0
Else
Dim n
If a.Text > 0 Then
b.Text = a.Text ^ (1 / 3)
Else
b.Text = "-" & a.Text ^ (1 / 3)
End If
End If
End If
a.Text = ""
End Sub
展开
 我来答
zwfyxy
2010-03-01 · TA获得超过127个赞
知道小有建树答主
回答量:343
采纳率:100%
帮助的人:99.9万
展开全部
Private Sub ok_Click()
Dim msga
Dim n

If a.Text = "" Then
msga = MsgBox("请输入被开方数!", vbCritical, "无法开平方")
b.Text = "----无法计算-----"
Else
If a.Text = 0 Then
b.Text = 0
Else
If a.Text > 0 Then
b.Text = a.Text ^ (1 / 3)
Else
b.Text = "-" & Abs(a.Text) ^ (1 / 3)
End If
End If
End If
a.Text = ""
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式