VB Fibonacci Code.. HELP!

I am trying to write a fibonacci sequence for Visual Basic. For some reason my code it not working.
I attached the code I have in eestuff ....


Public Class Form1

    Private Sub BtnProcessData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProcessData.Click
        Dim txtprevious1 As Long
        Dim txtprevious2 As Long
        Dim txtprevious3 As Long
        Dim i As int
        Dim txtnumber As Int
        txtprevious2 = 1
        txtcurrent = txtNumber

            for (i = 1 to txtcurrent)
            txtprevious3 = txtprevious3
            txtprevious1 = txtprevious2
            txtprevious2 = txtprevious1 + txtprevious3
        Next i

        txtnumber = txtprevious1
    End Sub

End Class
ashblynn02Asked:
Who is Participating?
 
Arthur_WoodConnect With a Mentor Commented:
On your form, add a wide TextBox, named txtSeries, and use this code:
Public Class Form1

    Private Sub BtnProcessData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProcessData.Click
       Dim previous1 As Long = 1
        Dim previous2 As Long
        Dim previous3 As Long
        Dim number As Long = 15
        Dim fibonacci As Long
        Dim i As Long
        previous2 = 1
        fibonacci = number

        For i = 1 To fibonacci

            previous3 = previous1
            previous1 = previous2
            previous2 = previous1 + previous3
            txtSeries.Text += previous1.ToString() + ";"
        Next
  End Sub
End Class

AW
0
 
dqmqCommented:
Please desk check your code.  I'd suggest doing a walkthru with a peer.  
0
 
ashblynn02Author Commented:
what do you mean desk check
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mankowitzCommented:
This should do it

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim count As Integer = Val(TextBox1.Text)
        If count < 3 OrElse count > 1000 Then
            MsgBox("Try something between 3 and 1000")
            Exit Sub
        End If

        Dim Fibo(count - 1) As Integer
        Fibo(0) = 1
        Fibo(1) = 1
        For x As Integer = 2 To count - 1
            Fibo(x) = Fibo(x - 1) + Fibo(x - 2)
        Next

        WholeSeries.Text = ""
        For x As Integer = 0 To count - 2
            WholeSeries.Text &= Fibo(x) & ", "
        Next
        WholeSeries.Text &= Fibo(count - 1)

        Result.Text = Fibo(count - 1)
    End Sub
End Class

0
 
ashblynn02Author Commented:
I uploaded my code with my object box
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Hi ashblynn02,

The zip file you uploaded to ee-stuff only contained the solution file.  You need to also include the forms that go with it...

So none of the solutions in your previous question helped you?
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22852012.html
0
 
dqmqCommented:
>what do you mean desk check

I mean, read your code and look for stupid mistakes, like this:

       txtprevious3 = txtprevious3

or like this:
       Dim i As int
       Dim txtnumber As Int
       txtcurrent = txtNumber
       for (i = 1 to txtcurrent)
0
 
ashblynn02Author Commented:
okay im sorry i didn't know what you meant
0
 
ashblynn02Author Commented:
I have it almost figured out I just can't figure out why it is not returning a result


Public Class Form1

    Private Sub BtnProcessData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProcessData.Click
        Dim previous1 As Long
        Dim previous2 As Long
        Dim previous3 As Long
        Dim number As Long
        Dim fibonacci As Integer
        Dim i As Integer
        previous2 = 1
        fibonacci = CInt(number)

        For i = 1 To fibonacci
            previous3 = previous3
            previous1 = previous2
            previous2 = previous1 + previous3
        Next i

        number = CInt(previous1)
    End Sub
End Class
0
 
mankowitzCommented:
Why do you have both fibonacci and number when they are the same?
Also, previous1-3 are numbered strangely, which makes reading your code difficult. You could make your code more understandable with something like this

current = prev1+prev2
prev2=prev1
prev1=current
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.