Hi Guys,

I am struggling with a small problem and was wondering if anyone would be kind enough to help...

I have to write a program showing (up to 30) of the first Fibonacci numbers in sequence.

Unfortunately, my programming skills are fairly poor - and I am having trouble with the whole thing!!

It has to be done in VB.NET

I have found the formula - but I basically need to incorporate it into my program - and I'm having a bit of trouble...

I would appreciate any help...

Thanks:sad:

Recommended Answers

All 14 Replies

Member Avatar for Dukane

Show us your code and what parts of it you are having trouble with. We dont do your homework on this board for you.

Show us your code and what parts of it you are having trouble with. We dont do your homework on this board for you.

The idea is to have a textbox and a listbox output the Fibonacci Sequence...

The user enters the number (via textbox) of Fibonacci numbers to be displayed. i.e. If the user enters 3 - then "0,1,1" will show in the listbox.. 5 - then "0,1,1,2,3" will show and so on....

As I have stated - I am a complete novice...:sad:

My code so far is as follows:

Dim Fibonacci() As Integer = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34,55,89,144,233,377,610}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Repeat As Integer
Repeat = CInt(TextBox1.Text)
ListBox1.DataSource = Fibonacci

I would be extremely grateful for any help! Thanks!


Member Avatar for Dukane

There is a very easy problem. You need to think about what you need to do here. I can give you a hint, you need a loop.

There is a very easy problem. You need to think about what you need to do here. I can give you a hint, you need a loop.

Hi Dukane,

I have tried the following code - but to no avail...

Dim Fibonacci() As Integer = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.DataSource = Fibonacci
Dim Repeat As Integer
Repeat = CInt(txtRepeat.Text)

Dim Counter As Integer
For Counter = 1 To Repeat Step 1
Next
Do
Loop Until Counter = Repeat


I am seriously fed up with this!!!

I thought that the "loop" would stop at the correct number!


:eek:

Is anything which I have written correct???

Please Help!

Member Avatar for Dukane

Ok, think of the pseudo code for this problem.

Take the input from the user, which is the number of digits in the sequence to print. This number also corresponds to the index of the array + 1. For example, if I enter "5" then you need to print whatever is in the array starting at 0 to 4.

If that doesn't help you, I don't know what will...beside writing the code for you.

I can tell you this...you are using the ListBox.DataSource property wrong. You have two loops, both which have no body. They don't do anything.

Hi Guys,

I am struggling with a small problem and was wondering if anyone would be kind enough to help...

I have to write a program showing (up to 30) of the first Fibonacci numbers in sequence.

Unfortunately, my programming skills are fairly poor - and I am having trouble with the whole thing!!

It has to be done in VB.NET

I have found the formula - but I basically need to incorporate it into my program - and I'm having a bit of trouble...

I would appreciate any help...

Thanks:sad:

hai

myself vidhya,just i am also a beginner i have a small idea about it .

create one form ,in that create one listbox (name it as lstdata) and button(name it as btnfibanocci).
change the text of the button to fibonacci .
double click the button(it mean we are writing the code in button event)
write the following code

private sub btnfibanocci_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfibanocci.Click

' it is used to clear the list box
lstdata.items.clear()

Dim a As integer 'a is a variable used to store the first fib number
Dim b As integer 'b is a variable used to store the 2nd fib number
Dim c As integer
Dim n As integer ' n indidicates the number of fib u need for eg 30

a=0 ' initialise the first fib number
b=1 ' initialise the Second fib number

lstData.Items.Add(a) 'i add 1st fib number in my list
lstData.Items.Add(b) 'i add 2nd fib number in my list

for n=2 to 30

c=a+b ' the third number is got by adding first two number=0+1=1

lstData.Items.Add(c) 'add to the list

b=a 'now the second number is changed to first number
b=c 'now the the third number is changed to 2nd number to be added


next
End Sub
........................................................................
NOW THE PROGRAM IS COMPLETED
IN THAT FORM IF U PRESS THAT FIBANOCCI BUTTON
IN THE NEARBY LIST BOX U CAN SEE THE FIBANOCCI NUMBERS
nearby each staement i give comment of it ok
if it is difficult to understand sorry

Member Avatar for Dukane

VIDHYAPREM,

Next time please read the forum rules before you give someone the answer to a homework problem.

VIDHYAPREM,

Next time please read the forum rules before you give someone the answer to a homework problem.

hai ,
just i am new member. i dn't know the forum rules.we should not answer like this or it had any mistake.please tell me.

here is it in VB6 code, should be easialy modifiabkle for VB.NET

Dim x As Integer
Dim y As Integer
Dim z As Integer
x = 1
y = 1
z = 1
For x = 1 To 100
z = x + y
x = y
y = z
MsgBox " " & z + 1
Next x

dont know if its right, made it up right now

hai ,
just i am new member. i dn't know the forum rules.we should not answer like this or it had any mistake.please tell me.

forum rules do not prohibit you from giving complete solutions, just discourages it. But you should probably take a few minutes to review the rules anyway.

general opinion is that people wont do it for you but will point you in the right direction

Thankyou very much for your help - it is much appreciated.

I am sorry about the fact that people discourage others from help, because sometimes the help you recieve can be very cryptic.
Not all people have the skills to jump straight into a program and do well. If I could help someone with a problem, then I would.

My dear Friend Vidhya....
The code which u sent is correct but there is a small mistake........In the end of the program it should like below......

lstData.Items.Add(c) 'add to the list

a = b
b = c

next
End Sub


U have written b=a if we give b=a then it wont increment.....ok.....Thanks for the code....Take care Bye

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.