tags:

views:

287

answers:

1

I am trying to write a code for Fibonacci series in VB, but some of the values in my series are incorrect. Can somebody help me with the code?

Below is what I have so far.

Private Function FibNumber(number As Integer) As Integer

If (number > 2) Then
    FibNumber = (FibNumber(number - 2) + FibNumber(number - 1))
Else
    FibNumber = 1
End If

End Function

Private Sub command1_click()
Dim x As Integer
x = Text1.Text
Call FibNumber(number)
End Sub
+3  A: 

Well, I did a quick search and I came up with the following in the first couple of results:

Private Function FibNumber(number As Integer) As Integer

If (number > 2) Then
    FibNumber = (FibNumber(number - 2) + FibNumber(number - 1)) 
Else
    FibNumber = 1
End If

End Function
Joseph
but u need to call the function to print..i guess
compgeek
@compgeek That's correct, I didn't assume how you planned to use the Fibonacci series, just how to calculate it.
Joseph
@joseph:then complete the code to print as well
compgeek