VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Generates and Displays the Fibonacci Series

by Sameet Natekar (6 Submissions)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 29th January 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Generates and Displays the Fibonacci Series

API Declarations


'3 command buttons (1 to generate the fib series, 1 to clear it and the 3rd to exit.
'you will also require a list box to display the series.
'Do not change the names of the components
' Fibonacci series is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34....... where a number in the series is the sum of the previous 2 nos.
'first 2 nos r 0 and 1.


Rate Generates and Displays the Fibonacci Series



If Text1.Text > 47 Then
MsgBox ("Please enter a number > 47 else you will get an 'Overload Error'")
Else
List1.Clear
Dim x, i As Integer
x = Text1.Text - 1
Dim fib(50) As Long
fib(0) = 0
fib(1) = 1
For i = 2 To x Step 1
fib(i) = fib(i - 2) + fib(i - 1)
Next
For i = 0 To x
List1.AddItem fib(i)
Next
End If
End Sub

Private Sub Command2_Click()
Dim rep As String
rep = MsgBox("Are you sure you want to clear the box?", vbYesNo, "Clearance Confirmation.")
If rep = vbYes Then
List1.Clear
End If
End Sub

Private Sub Command3_Click()
End
End Sub

Private Sub Text1_Change()
'Textbox will accept only nos, no alphabets, symbols or even decimal points.
Dim ltr As String
Dim dis As Integer
dis = 1
n = Len(Text1.Text)
For i = 1 To n
ltr = Mid(Text1.Text, i, 1)
If Not (ltr >= "0" And ltr <= "9") Then
dis = dis * 0
End If
Next
If dis = 0 Then
Command1.Enabled = False
Else
Command1.Enabled = True
End If
End Sub


Download this snippet    Add to My Saved Code

Generates and Displays the Fibonacci Series Comments

No comments have been posted about Generates and Displays the Fibonacci Series. Why not be the first to post a comment about Generates and Displays the Fibonacci Series.

Post your comment

Subject:
Message:
0/1000 characters