grierfield
Technical User
does anyone have a VB program module for fIBONACCI numbers?
thanks
thanks
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
That's not how it works, here at Tek-Tips. These are forums for professionals, who are experiencing problems with their tasks.does anyone have a VB program module for fIBONACCI numbers?
Sub Fibonacci()
Dim Fn() As Single 'Type Long required for a limit greater than 183
limit = 20 'Enter the series calculation limit here.
ReDim Fn(0 To limit) 'Size the array for the series limit
Fn(0) = 0 'Always 0
Fn(1) = 1 'Always 1
Fna = 0
Fnb = 1
Fnc = 0
Fnx = 0
'The first two numbers of the series are always 0 and 1
'the next number is then the sum of preceding two numbers
For x = 2 To limit
Fnx = Fna + Fnb
Fnc = Fnb
Fnb = Fnx
Fna = Fnc
Fn(x) = Fnx
Debug.Print x, Fn(x)'Prints Fn(2)... Fn(limit)
Next
Erase Fn() 'Clears the memory when finished.
End Sub