Results 1 to 17 of 17

Thread: Displaying a pattern of Fibonacci's sequence ....

  1. #1

    Thread Starter
    Lively Member heartisablack's Avatar
    Join Date
    Nov 2003
    Location
    new jersey
    Posts
    96

    Displaying a pattern of Fibonacci's sequence ....

    hey guys.

    i have been trying to display a 25 term pattern displaying the sequence of fibonacci's. for example ... 0, 1, 1, 2,3, 5 ... i can't seem to get it and i was wondering if anyone could help me out with maybe some ideas or just some sort a hint as to how to get it started, thanks.

  2. #2
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    Here's how I wrote it in JavaScript. I doubt it's too hard to convert to VB:
    Code:
    <html>
    <head>
    <title>Fibbionacci Sequence</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <script>
    var a=0
    var b=1
    var c=0
    for (i=0; i<25; i++)
    	{
    	c=a+b
    	document.write(c+",")
    	b=a
    	a=c
    	}
    </script>
    </body>
    </html>
    Have I helped you? Please Rate my posts.

  3. #3
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    OK, here's the VB code for it:
    Attached Files Attached Files
    Have I helped you? Please Rate my posts.

  4. #4

    Thread Starter
    Lively Member heartisablack's Avatar
    Join Date
    Nov 2003
    Location
    new jersey
    Posts
    96
    the downloadable form was good, but i dont need it to ask me how many i want .. like the text box does, but rather to just display 25 automaticaly .. if that is possible?

  5. #5
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    in that case, remove the button and textbox. Make the code run onLoad as opposed to onClick, and change the for loop to:
    for i=0 to 25
    ...
    Have I helped you? Please Rate my posts.

  6. #6

    Thread Starter
    Lively Member heartisablack's Avatar
    Join Date
    Nov 2003
    Location
    new jersey
    Posts
    96
    Private Sub cmdPattern8_Click()
    Dim inth As Double
    Dim inti As Double
    Dim intk As Double
    Dim intl As Double
    lstDisplay.Clear
    For inth = 0 To 25
    intk = inth + inti
    lstDisplay.AddItem intk
    Next inth


    End Sub

    what's wrong with that? am i just ****ing stupid?

  7. #7
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    Whole code:

    VB Code:
    1. Option Explicit
    2. Dim a As Double
    3. Dim b As Double
    4. Dim c As Double
    5. Dim i As Double
    6.  
    7. Private Sub Form_Load()
    8. lstSeq.Clear
    9. a = 0
    10. b = 1
    11. For i = 0 To 24
    12.     c = a + b
    13.     lstSeq.AddItem c
    14.     b = a
    15.     a = c
    16. Next i
    17. End Sub


    Where the list is calles lstSeq
    Last edited by Acidic; Nov 25th, 2003 at 04:08 PM.
    Have I helped you? Please Rate my posts.

  8. #8

    Thread Starter
    Lively Member heartisablack's Avatar
    Join Date
    Nov 2003
    Location
    new jersey
    Posts
    96
    i'm really new at this and trying to learn, but i really dont understand, i know that i need to use inth, and intk, and that inti is not needed. i only need inth, intk, n intI, and that inth and intk have the correct values, but it's hte intI that is messing me up.

  9. #9

    Thread Starter
    Lively Member heartisablack's Avatar
    Join Date
    Nov 2003
    Location
    new jersey
    Posts
    96
    okay i got it to work! i just need it to start at 0, so make it -1 to 24?

  10. #10
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    using my code:
    VB Code:
    1. Option Explicit
    2. Dim a As Double
    3. Dim b As Double
    4. Dim c As Double
    5. Dim i As Double
    6.  
    7. Private Sub Form_Load()
    8. lstSeq.Clear
    9. a = 0
    10. b = 1
    11. For i = 0 To 24
    12.     c = a + b
    13.     lstSeq.AddItem c
    14.     b = a
    15.     a = c
    16. Next i
    17. End Sub

    a is set to 0 and b set to 1
    It then loops through the loop 25 times, each time making c=a+b which it then adds to the list. Then b=a and a=c. This is so that one the next loop, then will add up to being the next term.

    All the i does is to make sure the loop runs through 25 times.
    Have I helped you? Please Rate my posts.

  11. #11

    Thread Starter
    Lively Member heartisablack's Avatar
    Join Date
    Nov 2003
    Location
    new jersey
    Posts
    96
    i finally understand what is happening, but i dont understand how to get 0 to be the first number, i tried different methods that resulted in all 0's and all negatives ...

  12. #12

    Thread Starter
    Lively Member heartisablack's Avatar
    Join Date
    Nov 2003
    Location
    new jersey
    Posts
    96
    nevermind! got it! thanks so much for everything.

  13. #13
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    the only way I can think of is forcing it to be so. Make the first item always 0.
    ie, before the loop, at 0 to the list (make sure to run the loop one time less in order to still get 25 terms)
    Have I helped you? Please Rate my posts.

  14. #14

    Thread Starter
    Lively Member heartisablack's Avatar
    Join Date
    Nov 2003
    Location
    new jersey
    Posts
    96
    haha what i did was before the loop began, i made a lstdisplay.additem=a , and then the loop began, i have to do 2 more of these patterns now ... one with this pattern ... 1,3,6,10,5 .. like 1+2=3+3=6+4=10 ... so that each one has the next number added to it, i think i have an idea of what to do nad then the second one is i have to make it add all the digits between 1 and 100 together .... i'm goign to try and do this, if i can't get it, you think you might be able to help me out? i really am learning, that is why i love these forums becuase you just dont give it away, you make people learn .. thanks ...

  15. #15
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    well, if you need help, just post.
    Have I helped you? Please Rate my posts.

  16. #16

    Thread Starter
    Lively Member heartisablack's Avatar
    Join Date
    Nov 2003
    Location
    new jersey
    Posts
    96
    for the first of the two, i tried this ....

    Private Sub cmdPattern9_Click()

    Dim q As Double
    Dim l As Double
    Dim k As Double
    Dim q As Double
    lstDisplay.Clear
    q = 0
    l = 1
    For k = 0 To 24
    d = q + l
    lstDisplay.AddItem d
    l = q + 1
    q = d
    Next k
    End Sub

    and it didnt work, i mena i think it looks good, but obviously it's not, what is wrong?

  17. #17

    Thread Starter
    Lively Member heartisablack's Avatar
    Join Date
    Nov 2003
    Location
    new jersey
    Posts
    96

    Thumbs up

    ah, nevermind, holy ****! i got it my own!
    you'll feel better when you cannot feel at all ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width