Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim li_Term As Integer
        Dim li_a As Integer = 0
        Dim li_b As Integer = 1
        Dim li_fib As Integer = 0
        Dim li_c As Integer
        While li_fib <= 9
            TextBox1.Text = TextBox1.Text + li_Term.ToString + ControlChars.NewLine
            li_a = li_b
            li_Term = li_a + li_b
            li_c = li_c + 1
        End While
Posted

Try this one.. It works..

VB
Dim li_a As Integer = 1
Dim li_b As Integer = 1
Dim li_fib As Integer = 0
TextBox1.Text = li_b.ToString + ControlChars.NewLine
While li_fib <= 9

    TextBox1.Text = TextBox1.Text + li_b.ToString + ControlChars.NewLine
    li_b = li_b + li_a
    li_a = li_b - li_a
    li_fib = li_fib + 1

End While
 
Share this answer
 
[This is not an answer, should be removed — SA]

VB
Dim li_Term As Integer
       Dim li_Term As Integer = 1
       Dim li_Termprev As Integer = 0
       Dim li_TempBuff = 0
       Dim li_fib As Integer = 0
       While li_fib <= 9
           li_TermBuff = li_Term
           li_Term = li_Term + li_Termprev
           li_Termprev = li_TermBuff
           TextBox1.Text = TextBox1.Text + li_Term.ToString + ControlChars.NewLine           
           li_fib = li_fib + 1
       End While
 
Share this answer
 
v4
It will take a long time.
In fact it will never return.

Since you don't change the value of li_fib inside the loop, the while condition will always be met.
Perhaps if you add the line
VB
li_fib = li_fib + 1
inside the loop, it might work better...
 
Share this answer
 
Comments
La Moth 9-Jul-12 6:27am    
Ok but after I midified the code it is like this and prints the series as
0
2
2
2
2
2
2
2
2
2
OriginalGriff 9-Jul-12 6:37am    
I didn't say your code was right! :laugh:
It isn't, which is why you have a problem.
Now starts the fun bit: debugging!
I could just tell you what the problem is, but this is a nice, simple piece of code so it should be pretty easy for you to work it out. And at the same time, learn to use the most powerful tool in your coding arsenal: The Debugger.

Start by putting a breakpoint on the first line in the loop. (See the VS menu under Debug - just put the cursor in the line, and "toggle breakpoint" - a red dot will appear to the left of the line.)

Run your program, and it will stop when it hits the breakpoint. You can then look at your data, and single step through each line.
How does your data change each time?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900