本文介绍了我的datagridview中的天数没有增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码在ndays有问题。我不知道我是否正确。



My code has problem in ndays. i dont know if im doing right.

Private Sub ComputeLedger()
        Dim interest = txtIntRate1.Text
        Dim interest2 = txtIntRate2.Text
        Dim princiapalLoan = txtBalAmortize.Text
        Dim matValue = txtMoAmort1.Text
        Dim matValue2 = txtMoAmort2.Text
        Dim dblMat As Double = Decimal.Parse(matValue, Globalization.NumberStyles.Currency)
        matValue = dblMat.ToString(Format("###,###,###.#0", "Standard"))
        Dim dblMat2 As Double = Decimal.Parse(matValue2, Globalization.NumberStyles.Currency)
        matValue2 = dblMat2.ToString(Format("###,###,###.#0", "Standard"))

        Dim effDate = dtpValueDate.Value
        Dim dueDate = dtpFirstDueDate.Value
        Dim firstdueDate = DateTimePicker1.Value
        Dim secondeffDate = DateTimePicker2.Value

        Dim i As Integer
        Dim weekInt As Integer
        Dim weekInt3 As Integer
        Dim weekInt2 As Integer = Val(txtTerms2.Text)
        Dim durations As Integer = Val(txtTerms1.Text)
        Dim durations2 As Integer = Val(lblTotalTerms.Text)
        'DataGridView1.Rows.Clear()

        Dim ndays As Integer
        ndays = DateDiff("d", firstdueDate, secondeffDate)

        Dim areturnv As Double '= (princiapalLoan / durations2)
        Dim dblret2 As Double = Decimal.Parse(areturnv, Globalization.NumberStyles.Currency)
        Dim ainterest As Double '= ((princiapalLoan * (interest2)) * (ndays / 365))
        Dim dblint2 As Double = Decimal.Parse(ainterest, Globalization.NumberStyles.Currency)
        Dim princ As Double '= (matValue - ainterest)
        Dim dblprin2 As Double = Decimal.Parse(princ, Globalization.NumberStyles.Currency)
        Dim tolamt = (princiapalLoan)
        Dim dblamt2 As Double = Decimal.Parse(tolamt, Globalization.NumberStyles.Currency)
        Dim tolamt3 As Double '= (princiapalLoan - princ)
        Dim dblamt3 As Double = Decimal.Parse(tolamt3, Globalization.NumberStyles.Currency)
        'Dim tolamt4 As Double '= (princiapalLoan - princ)
        Dim dblamt4 As Integer 'Double = Decimal.Parse(tolamt4, Globalization.NumberStyles.Currency)

       Do While durations < durations2
            durations += 1
            weekInt3 += 1

            secondeffDate = firstdueDate.AddMonths(weekInt3)
            If secondeffDate.DayOfWeek = DayOfWeek.Saturday Then
                secondeffDate = secondeffDate.AddDays(2)
            ElseIf secondeffDate.DayOfWeek = DayOfWeek.Sunday Then
                secondeffDate = secondeffDate.AddDays(1)
            End If

            Select Case dblamt4
                Case "01" 'January"
                    dblamt4 = "31"
                Case "02" 'February"
                    dblamt4 = "28"
                Case "03" 'March"
                    dblamt4 = "31"
                Case "04" 'April"
                    dblamt4 = "30"
                Case "05" 'May"
                    dblamt4 = "31"
                Case "06" 'June"
                    dblamt4 = "30"
                Case "07" 'July"
                    dblamt4 = "31"
                Case "08" 'August"
                    dblamt4 = "31"
                Case "09" 'September"
                    dblamt4 = "30"
                Case "10" 'October"
                    dblamt4 = "31"
                Case "11" 'November"
                    dblamt4 = "30"
                Case "12" 'December"
                    dblamt4 = "31"
            End Select

'my problem is in code. 
            ndays = DateDiff(DateInterval.Day, firstdueDate.AddDays(dblamt4), firstdueDate.AddMonths(weekInt3))
            dblret2 = ((princiapalLoan * (interest2)) * (ndays / 365))

            dblint2 = dblMat2 - dblret2
            dblamt3 = dblamt3 - dblint2

            DataGridView1.Rows.Add(secondeffDate.ToString("MM/dd/yyyy"), _
                                    dblMat2.ToString(Format("###,###,###.#0", "Standard")), _
                                    ndays, _
                                    dblret2.ToString(Format("###,###,###.#0", "Standard")), _
                                    dblint2.ToString(Format("###,###,###.#0", "Standard")), _
                                    dblamt3.ToString(Format("###,###,###.#0", "Standard")))
        Loop


    End Sub

推荐答案

ndays = DateDiff(DateInterval.Day, firstdueDate.AddDays(dblamt4), firstdueDate.AddMonths(weekInt3))





你在哪里在firstdueDate和一些固定金额之间的天数(比如31)重新做差异。



和你的周t3随着每次迭代而增加,因此您在固定数量和增加的月数之间存在差异



我认为您需要在该计算中使用secondeffDate ...



也就是说,我没有读完你的整个代码,只是最后一个循环与ndays所以也许我错过了什么。



即使它不是secondeffDate,它肯定是沿着那条线。



最后,虽然你的解释解释了什么是错的,但它并没有什么,它应该做什么,所以我不能肯定地说解决方案是什么,只是你增加差异的原因。



Where you're doing difference in days between firstdueDate and some fixed amount (say 31)

And your weekInt3 is increasing with each iteration so you have difference between fixed number and increasing number of months

I think you need to use secondeffDate in that calc...

That said, I didn't read whole of your code, just that last loop with ndays so maybe I'm missing something.

Even if it is not secondeffDate, it definitely is something along that line.

Finally, while your explanation explains what is wrong, it doesn't give anything about what it SHOULD do so I cannot say definitely WHAT the solution is, just the reason why you have increasing difference.


这篇关于我的datagridview中的天数没有增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 14:17