如何计算vb.net中的年数总和 [英] How to calculate sum of years digit in vb.net

查看:64
本文介绍了如何计算vb.net中的年数总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码工作正常,小问题。我的问题是,我怎样才能让BegValue以正确的顺序工作。请它只是让我头疼的乞讨。请有人帮助我。我求求!!!



提前致谢。



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.

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

推荐答案

那么你做了什么,你没想到,或者没有做到这一点?

你给它的数据是什么?你期待什么结果?你得到了什么结果?



论文是我们所能提出的所有问题;没有他们,没有人能分辨出什么是错的。



幸运的是,你可以。

所以,回答这些问题,然后使用调试器来查看你的程序正在做什么。

如果在For循环上放置断点,也在接下来,您可以计算出在每次迭代之前代码是否正常工作时您希望看到的值,并将这些值与最终实际获得的值进行比较。在某些时候,你会得到一个不同 - 这意味着你可以专注于特定的迭代。

重新启动程序,并将其运行回到该循环的开头 - 所以它将执行迭代,给你错误的结果。这一次,使用调试器的单步功能一次执行一行,在执行之前计算出正确工作时所期望的值。当你发现差异时,你可以仔细看看具体的线路,并且知道差异并不是很难找出问题所在。



我们不能为您做任何事情 - 我们没有任何相关信息!

祝您好运!
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!


是的,如您所说我昨天能够自己解决它并感谢你的建议。



见下面的代码



Yes as you said I was able to solve it yesterday by my self and thank you for your advice.

see below code

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


这篇关于如何计算vb.net中的年数总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆