怎么在VB语言中给函数过程传递参数?
我编写的一段程序在VB语言中给函数过程传递参数?PrivateSubForm_Click()DimsAsInteger,xAsInteger,yAsIntegerDimn...
我编写的一段程序在VB语言中给函数过程传递参数?
Private Sub Form_Click()
Dim s As Integer, x As Integer, y As Integer
Dim n, p, q As Integer
s = 5
x = 2
y = 3
a = myfunc(s, x, y)
Print "第" & 5 & "项是"; a
End Sub
Function myfunc(s As Integer, x As Integer, y As Integer)
If s = 1 Then
myfunc = x
ElseIf s = 2 Then
myfunc = y
Else
myfunc = myfunc(s - 2) + myfunc(s - 1)
End If
End Function 展开
Private Sub Form_Click()
Dim s As Integer, x As Integer, y As Integer
Dim n, p, q As Integer
s = 5
x = 2
y = 3
a = myfunc(s, x, y)
Print "第" & 5 & "项是"; a
End Sub
Function myfunc(s As Integer, x As Integer, y As Integer)
If s = 1 Then
myfunc = x
ElseIf s = 2 Then
myfunc = y
Else
myfunc = myfunc(s - 2) + myfunc(s - 1)
End If
End Function 展开
推荐于2018-04-21
展开全部
Private Sub Form_Click()
Dim s As Integer
Dim x As Integer
Dim y As Integer
s = 5
x = 2
y = 3
a = myfunc(s, x, y)
Print "第" & 5 & "项是:" & a
End Sub
Function myfunc(ByVal s As Integer, ByVal x As Integer, ByVal y As Integer)
If s = 1 Then
myfunc = x
ElseIf s = 2 Then
myfunc = y
Else
myfunc = myfunc(s - 2, x, y) + myfunc(s - 1, x, y)
End If
End Function
上述的代码在遍历中,其中有五次是符合计算要求的第一次的值是:2第二次的值是:3第三次的值是:3第四次的值是:2第五次的值是:3 即2+3+3+2+3=13
Dim s As Integer
Dim x As Integer
Dim y As Integer
s = 5
x = 2
y = 3
a = myfunc(s, x, y)
Print "第" & 5 & "项是:" & a
End Sub
Function myfunc(ByVal s As Integer, ByVal x As Integer, ByVal y As Integer)
If s = 1 Then
myfunc = x
ElseIf s = 2 Then
myfunc = y
Else
myfunc = myfunc(s - 2, x, y) + myfunc(s - 1, x, y)
End If
End Function
上述的代码在遍历中,其中有五次是符合计算要求的第一次的值是:2第二次的值是:3第三次的值是:3第四次的值是:2第五次的值是:3 即2+3+3+2+3=13
2014-01-22
展开全部
Option ExplicitPrivate x, y As Integer 'x为第一项值,y为第二项值Private Sub Form_Click()
Dim s, a As Integer
s = 5
x = 2
y = 3
a = myfunc(s)
Print "第" & s & "项是" & a
End Sub
Function myfunc(ByVal s As Integer)
If s = 1 Then
myfunc = x
ElseIf s = 2 Then
myfunc = y
Else
myfunc = myfunc(s - 2) + myfunc(s - 1) '递归调用
End If
End Function
Dim s, a As Integer
s = 5
x = 2
y = 3
a = myfunc(s)
Print "第" & s & "项是" & a
End Sub
Function myfunc(ByVal s As Integer)
If s = 1 Then
myfunc = x
ElseIf s = 2 Then
myfunc = y
Else
myfunc = myfunc(s - 2) + myfunc(s - 1) '递归调用
End If
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询