齿轮转动 gif:VB问题:下面代码有什么问题?

来源:百度文库 编辑:高校问答 时间:2024/05/09 01:04:15
Function f(n as integer) as double
If n>0 then
f=n*f(n-1)
else
f=1
end if
end function
sub Form1_click()
Dim num as Integer
num=InputBox("")
d=f(num)
print d
end sub

Function f(n As Integer) As Double
If n > 0 Then
f = n * f(n - 1)
Else
f = 1
End If
End Function
Sub command1_click()
Dim num As Integer
num = InputBox("")
d = f(num)
Print d
End Sub
加个COMMAND控件,用command1_click()事件就可以解决了!!

Function f(ByVal n As Integer) As Double
If n > 0 Then
f = n * f(n - 1)
Else
f = 1
End If
End Function
Sub Form_click()'不是Form1
Dim num as integer
dim d As double'变量d未定义
num = Val(InputBox(""))
d = f(num)
Print d
End Sub