Click here to Skip to main content
15,887,957 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Below code is working fine with small problem. My problem here is, how can i get the BegValue working in a proper order. please it is only the begvalue that is giving me a headache. Please some one help me. I'm begging !!!

Thanks in advance.

VB
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim Cost, Scrap, Life, Period, BegValue, EndValue, Deprec, AccumDeprec, YearPurch As Double
        Dim Fmt As String = "###,##0.00"

        Cost = txtcost.Text
        Scrap = txtscrap.Text
        Life = txtlife.Text
        YearPurch = txtyear.Text
        Period = txtlife.Text



        DataGridView1.ColumnCount = 6
        DataGridView1.Columns(0).Name = "Begin Year"
        DataGridView1.Columns(1).Name = "Begin Value"
        DataGridView1.Columns(2).Name = "Depreciation"
        DataGridView1.Columns(3).Name = "Accum.Depreciation"
        DataGridView1.Columns(4).Name = "End Value"
        DataGridView1.Columns(5).Name = "End Year"

        DataGridView1.Rows.Clear()

        For Period = 1 To Life

            BegValue = Cost
            Deprec = SYD(Cost, Scrap, Life, Period)
            AccumDeprec += Deprec
            EndValue = BegValue - Deprec

            Dim row As String() = New String() {YearPurch, _
                                                 FormatNumber(BegValue), _
                                                 FormatNumber(Deprec), _
                                                 FormatNumber(AccumDeprec), _
                                                 FormatNumber(EndValue), _
                                                 YearPurch}



            DataGridView1.Rows.Add(row)

            BegValue = EndValue

            If Period = Life - 1 Then

                Deprec = BegValue - Scrap

            Else

                Deprec = SYD(Cost, Scrap, Life, Period)

            End If

            YearPurch += 1

        Next

    End Sub



End Class
Posted

So what is it doing that you don't expect, or not doing that you do?
What data are you giving it? What results are you expecting? What results are you getting?

Theses are all questions we can;t answer, and without them nobody can tell what is wrong.

Fortunately, you can.
So, answer those questions, and then use the debugger to look at what your program is doing.
If you put a breakpoint on the For loop, and also on the Next, you can work out what values you expect to see if the code is working before each iteration and compare those with the values you actually get at the end. At some point, you will get a difference - which means you can focus on that particular iteration.
Restart the program, and run it back to the start of that loop - so it's about to execute the iteration that gave you the "wrong" results. This time, use the single step feature of the debugger to execute each line one at a time, working out before you execute it what values you would expect if it was working correctly. When you find a difference, then you can look closer at the specific line and with the difference known it shouldn't be too hard to work out what the problem is.

Be we can't do any of that for you - we don't have any of the relevant information!
Good luck!
 
Share this answer
 
Yes as you said I was able to solve it yesterday by my self and thank you for your advice.

see below code

VB
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim Cost, Scrap, Life, Period, BegValue, EndValue, Deprec, AccumDeprec, YearPurch As Double
        Dim Fmt As String = "###,##0.00"

        Cost = TxtCost.Text
        Scrap = txtscrap.Text
        Life = TxtLife.Text
        YearPurch = txtYear.Text
        Period = TxtLife.Text



        DataGridView1.ColumnCount = 6
        DataGridView1.Columns(0).Name = "Begin Year"
        DataGridView1.Columns(1).Name = "Begin Value"
        DataGridView1.Columns(2).Name = "Depreciation"
        DataGridView1.Columns(3).Name = "Accum.Depreciation"
        DataGridView1.Columns(4).Name = "End Value"
        DataGridView1.Columns(5).Name = "End Year"

        DataGridView1.Rows.Clear()

        BegValue = Cost

        For Period = 1 To Life

            Deprec = SYD(Cost, Scrap, Life, Period)
            AccumDeprec += Deprec
            EndValue = BegValue - Deprec

            Dim row As String() = New String() {YearPurch, _
                                                 FormatNumber(BegValue), _
                                                 FormatNumber(Deprec), _
                                                 FormatNumber(AccumDeprec), _
                                                 FormatNumber(EndValue), _
                                                 YearPurch}



            DataGridView1.Rows.Add(row)

            BegValue = EndValue


            If Period = Life - 1 Then

                Deprec = BegValue - Scrap

            Else

                Deprec = SYD(Cost, Scrap, Life, Period)

            End If

            YearPurch += 1

        Next

    End Sub



End Class
 
Share this answer
 

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