VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Fibonacci Algorithm recursively creates a Fibonacci Series which is a series where each member is c

by http://www.paretoanalysts.com (5 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 14th December 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Fibonacci Algorithm recursively creates a Fibonacci Series which is a series where each member is calculated from the previous two members and

Rate Fibonacci Algorithm recursively creates a Fibonacci Series which is a series where each member is c




On Error GoTo ErrorHandler

'**********************************************************************************************************
'
'Purpose:           An Algorithm that creates the Fibonacci members of a series.
'
'Argument(s):       Start_Number     -   The number to start the Fibonacci series with.
'
'Source:            http://www.paretoanalysts.com
'
'Author:            Pareto Analysts
'
'Creation Date:     December 1, 2001
'
'Description:       Creates a Fibonacci series F(N) = F(N-1) + F(N-2) , where F(0) = F(1) = 1.'
'                   E.g. Fibonacci(20). It recursively calls the Fibonacci function to create the series.
'                   Each member F(N) is the sum of the two previous members F(N-1) and F(N-2).
'
'                   It calls the Private Function Fib(N) which creates the members one at a time, recursively
'
'Return Value:      The Fibonacci Series of the number passed to the function.
'
'Return Type:       Variant
'
'
'
'Warranty :         No claim is made as to the accuracy or fitness of this algorithm. The use of this
'                   algorithm is at your own risk and choice and the author is not liable in anyway
'                   for its use or damages that may occur as a result of its use.
'
'Copyright:         The use or distribution of this algorithm is free provided that it is
'                   used or distributed along with this header notice and this header notice
'                   has not been modified in any way. If this algorithm is used in a compiled form then
'                   the header notice must also be placed in a readme.txt file
'
'Inquiries:         Inquiries about this algorithm, data mining, statistical analysis and data analysis
'                   can be directed to http://www.paretoanalysts.com
'
'**********************************************************************************************************
    

Do While (Start_Number >= 0)                                                'Build the Fibonacci Series

    Fibonacci = Fibonacci & "," & Fib(Start_Number)
    Start_Number = Start_Number - 1
    
Loop
     
     
Fibonacci = Trim(Replace(Fibonacci, ",", "", 1, 1, vbTextCompare))          'Remove any leading commas and spaces
    
    
    
Exit_ErrorHandler:
    Exit Function
    
    
ErrorHandler:
    MsgBox Err.Number & " " & Err.Description, vbInformation, "www.paretoanalysts.com Fibonacci"
    Resume Exit_ErrorHandler


End Function




Private Function Fib(ByVal N As Double) As Double

On Error GoTo ErrorHandler

'**********************************************************************************************************
'
'Purpose:           A Recursive Algorithm that creates the Fibonacci numbers of a series.
'
'Argument(s):       N     -   The number to start the Fibonacci series with.
'
'Source:            http://www.paretoanalysts.com
'
'Author:            Pareto Analysts
'
'Creation Date:     December 1, 2001
'
'Description:       Creates the Nth member of a Fibonacci series.
'
'
'Return Value:      The Nth. member of the Fibonacci series.
'
'Return Type:       Double
'
'
'
'Warranty :         No claim is made as to the accuracy or fitness of this algorithm. The use of this
'                   algorithm is at your own risk and choice and the author is not liable in anyway
'                   for its use or damages that may occur as a result of its use.
'
'Copyright:         The use or distribution of this algorithm is free provided that it is
'                   used or distributed along with this header notice and this header notice
'                   has not been modified in any way. If this algorithm is used in a compiled form then
'                   the header notice must also be placed in a readme.txt file
'
'Inquiries:         Inquiries about this algorithm, data mining, statistical analysis and data analysis
'                   can be directed to http://www.paretoanalysts.com
'
'**********************************************************************************************************
    
        
    If (N = 0) Or (N = 1) Then                                      'F(0) and F(1) in a Fibonacci series are equal to 1
    
        Fib = 1
        
    Else
       
        Fib = Fib(N - 1) + Fib(N - 2)                              'F(N) = F(N-1) + F(N-2)
        
               
    End If

    
    
Exit_ErrorHandler:
    Exit Function
    
    
ErrorHandler:
    MsgBox Err.Number & " " & Err.Description, vbInformation, "www.paretoanalysts.com Fibonacci.fib"
    Resume Exit_ErrorHandler


End Function



Download this snippet    Add to My Saved Code

Fibonacci Algorithm recursively creates a Fibonacci Series which is a series where each member is c Comments

No comments have been posted about Fibonacci Algorithm recursively creates a Fibonacci Series which is a series where each member is c. Why not be the first to post a comment about Fibonacci Algorithm recursively creates a Fibonacci Series which is a series where each member is c.

Post your comment

Subject:
Message:
0/1000 characters