一个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 展开
以下是代码:
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 展开
1个回答
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询