VB编程中必选参数什么意思
有个求pi的近似值的程序,要求用VB过程编写,我写的为何出现编译错误:缺少:)和必选参数错误.程序如下:Subsum(nAsInteger)n=InputBox("输入n...
有个求pi的近似值的程序,要求用VB过程编写,我写的为何出现编译错误:缺少:)和必选参数错误.
程序如下:Sub sum(n As Integer)
n = InputBox("输入n值")
Dim i As Integer
sum = 0
For i = 1 To n
sum = sum + (-1)^(i-1)*(1/(2i-1))
Next i
Print "4*sum="; 4 * sum
End Sub
Private Sub Command1_Click()
Dim a As Integer
a = InputBox("输入a值")
sum a
End Sub
望各位大哥帮帮忙。谢了。 展开
程序如下:Sub sum(n As Integer)
n = InputBox("输入n值")
Dim i As Integer
sum = 0
For i = 1 To n
sum = sum + (-1)^(i-1)*(1/(2i-1))
Next i
Print "4*sum="; 4 * sum
End Sub
Private Sub Command1_Click()
Dim a As Integer
a = InputBox("输入a值")
sum a
End Sub
望各位大哥帮帮忙。谢了。 展开
3个回答
展开全部
你那个sub应该改为function,另有一句多余的,其它对照一下改就可以了:
Private Function sum(n As Integer)
Dim i As Integer
sum = 0
For i = 1 To n
sum = sum + (-1) ^ (i - 1) * (1 / (2 * i - 1))
Next i
Print "4*sum="; 4 * sum
End Function
Private Sub Command1_Click()
Dim a As Integer
a = InputBox("输入a值")
sum a
End Sub
Private Function sum(n As Integer)
Dim i As Integer
sum = 0
For i = 1 To n
sum = sum + (-1) ^ (i - 1) * (1 / (2 * i - 1))
Next i
Print "4*sum="; 4 * sum
End Function
Private Sub Command1_Click()
Dim a As Integer
a = InputBox("输入a值")
sum a
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
程序如下:
Function sum(n As Integer)
n = InputBox("输入n值")
Dim i As Integer
sum = 0
For i = 1 To n
sum = sum + (-1)^(i-1)*(1/(2i-1))
Next i
Print "4*sum="; 4 * sum
End Sub
Private Sub Command1_Click()
Dim a As Integer,b As Double
a = InputBox("输入a值")
b=sum(a)
End Sub
Function sum(n As Integer)
n = InputBox("输入n值")
Dim i As Integer
sum = 0
For i = 1 To n
sum = sum + (-1)^(i-1)*(1/(2i-1))
Next i
Print "4*sum="; 4 * sum
End Sub
Private Sub Command1_Click()
Dim a As Integer,b As Double
a = InputBox("输入a值")
b=sum(a)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |