Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 9-Jul-12 1:10am
La Moth478
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
li_fib = li_fib + 1
inside the loop, it might work better...
  Permalink  
Comments
Tefo Sean Mothowe at 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 at 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?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try this one.. It works..
 
 
        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
 
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

[This is not an answer, should be removed — SA]
 
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
  Permalink  
v4

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100