以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]采用代码进行计算数据时导致项目直接关闭的问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=103366)

--  作者:1452565001
--  发布时间:2017/7/6 16:03:00
--  [求助]采用代码进行计算数据时导致项目直接关闭的问题

我想制作一张表能自动生成36期等额本息的数据。A表示本金 i表示每月利息 n表示期数  i1、i2 ...表示每一期应收的利息金额  a1、a2 ...表示每期应收的本金  z1、z2 ...表示每期应收的本金和利息的和  s1、s2 ...表示本期后剩余未还的本金。

下面是代码,写在DataColChanged事件里,20期以内的金额都可以顺利进行计算,结果也是正确的,但是当n的值大于20(比如采用21时),就会导致项目直接关闭。列是数据列,采用的类型是高精度小数。请老师指点。

 

If e.DataRow.IsNull("n") = False AndAlso e.DataRow.IsNull("i") = False AndAlso e.DataRow.IsNull("A") = False Then  \'第一期
    e.DataRow("z1") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
    e.DataRow("a1") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 0 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
    e.DataRow("i1") = e.DataRow("z1")-e.DataRow("a1")
    e.DataRow("s1") = e.DataRow("A")-e.DataRow("a1")
    If e.DataRow("s1") <> 0 And e.DataRow("n") >= 2 Then \'第二期
        e.DataRow("z2") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
        e.DataRow("a2") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 1 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
        e.DataRow("i2") = e.DataRow("z2")-e.DataRow("a2")
        e.DataRow("s2") = e.DataRow("s1")-e.DataRow("a2")
        If e.DataRow("s2") <> 0 And e.DataRow("n") >= 3 Then
            e.DataRow("z3") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
            e.DataRow("a3") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 2 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
            e.DataRow("i3") = e.DataRow("z3")-e.DataRow("a3")
            e.DataRow("s3") = e.DataRow("s2")-e.DataRow("a3")
            If e.DataRow("s3") <> 0 And e.DataRow("n") >= 4 Then
                e.DataRow("z4") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                e.DataRow("a4") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 3 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                e.DataRow("i4") = e.DataRow("z4")-e.DataRow("a4")
                e.DataRow("s4") = e.DataRow("s3")-e.DataRow("a4")
                If e.DataRow("s4") <> 0 And e.DataRow("n") >= 5 Then
                    e.DataRow("z5") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                    e.DataRow("a5") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 4 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                    e.DataRow("i5") = e.DataRow("z5")-e.DataRow("a5")
                    e.DataRow("s5") = e.DataRow("s4")-e.DataRow("a5")
                    If e.DataRow("s5") <> 0 And e.DataRow("n") >= 6 Then
                        e.DataRow("z6") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                        e.DataRow("a6") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 5 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                        e.DataRow("i6") = e.DataRow("z6")-e.DataRow("a6")
                        e.DataRow("s6") = e.DataRow("s5")-e.DataRow("a6")
                        If e.DataRow("s6") <> 0 And e.DataRow("n") >= 7 Then
                            e.DataRow("z7") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                            e.DataRow("a7") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 6 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                            e.DataRow("i7") = e.DataRow("z7")-e.DataRow("a7")
                            e.DataRow("s7") = e.DataRow("s6")-e.DataRow("a7")
                            If e.DataRow("s7") <>  0 And e.DataRow("n") >= 8 Then
                                e.DataRow("z8") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                e.DataRow("a8") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 7 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                e.DataRow("i8") = e.DataRow("z8")-e.DataRow("a8")
                                e.DataRow("s8") = e.DataRow("s7")-e.DataRow("a8")
                                If e.DataRow("s8") <> 0 And e.DataRow("n") >= 9 Then
                                    e.DataRow("z9") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                    e.DataRow("a9") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 8 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                    e.DataRow("i9") = e.DataRow("z9")-e.DataRow("a9")
                                    e.DataRow("s9") = e.DataRow("s8")-e.DataRow("a9")
                                    If e.DataRow("s9") <> 0 And e.DataRow("n") >= 10 Then
                                        e.DataRow("z10") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                        e.DataRow("a10") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 9 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                        e.DataRow("i10") = e.DataRow("z10")-e.DataRow("a10")
                                        e.DataRow("s10") = e.DataRow("s9")-e.DataRow("a10")
                                        If e.DataRow("s10") <> 0 And e.DataRow("n") >= 11 Then
                                            e.DataRow("z11") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                            e.DataRow("a11") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 10 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                            e.DataRow("i11") = e.DataRow("z11")-e.DataRow("a11")
                                            e.DataRow("s11") = e.DataRow("s10")-e.DataRow("a11")
                                            If e.DataRow("s11") <> 0 And e.DataRow("n") >= 12 Then
                                                e.DataRow("z12") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                e.DataRow("a12") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 11 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                e.DataRow("i12") = e.DataRow("z12")-e.DataRow("a12")
                                                e.DataRow("s12") = e.DataRow("s11")-e.DataRow("a12")
                                                If e.DataRow("s12") <> 0 And e.DataRow("n") >= 13 Then
                                                    e.DataRow("z13") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                    e.DataRow("a13") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 12 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                    e.DataRow("i13") = e.DataRow("z13")-e.DataRow("a13")
                                                    e.DataRow("s13") = e.DataRow("s12")-e.DataRow("a13")
                                                    If e.DataRow("s13") <> 0 And e.DataRow("n") >= 14 Then
                                                        e.DataRow("z14") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                        e.DataRow("a14") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 13 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                        e.DataRow("i14") = e.DataRow("z14")-e.DataRow("a14")
                                                        e.DataRow("s14") = e.DataRow("s13")-e.DataRow("a14")
                                                        If e.DataRow("s14") <> 0 And e.DataRow("n") >= 15 Then
                                                            e.DataRow("z15") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                            e.DataRow("a15") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 14 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                            e.DataRow("i15") = e.DataRow("z15")-e.DataRow("a15")
                                                            e.DataRow("s15") = e.DataRow("s14")-e.DataRow("a15")
                                                            If e.DataRow("s15") <> 0 And e.DataRow("n") >= 16 Then
                                                                e.DataRow("z16") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                e.DataRow("a16") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 15 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                e.DataRow("i16") = e.DataRow("z16")-e.DataRow("a16")
                                                                e.DataRow("s16") = e.DataRow("s15")-e.DataRow("a16")
                                                                If e.DataRow("s16") <> 0 And e.DataRow("n") >= 17 Then
                                                                    e.DataRow("z17") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                    e.DataRow("a17") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 16 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                    e.DataRow("i17") = e.DataRow("z17")-e.DataRow("a17")
                                                                    e.DataRow("s17") = e.DataRow("s16")-e.DataRow("a17")
                                                                    If e.DataRow("s17") <> 0 And e.DataRow("n") >= 18  Then
                                                                        e.DataRow("z18") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                        e.DataRow("a18") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 17 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                        e.DataRow("i18") = e.DataRow("z18")-e.DataRow("a18")
                                                                        e.DataRow("s18") = e.DataRow("s17")-e.DataRow("a18")
                                                                        If e.DataRow("s18") <> 0 And e.DataRow("n") >= 19 Then
                                                                            e.DataRow("z19") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                            e.DataRow("a19") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 18 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                            e.DataRow("i19") = e.DataRow("z19")-e.DataRow("a19")
                                                                            e.DataRow("s19") = e.DataRow("s18")-e.DataRow("a19")
                                                                            If e.DataRow("s19") <> 0 And e.DataRow("n") >= 20 Then
                                                                                e.DataRow("z20") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                e.DataRow("a20") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 19 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                e.DataRow("i20") = e.DataRow("z20") - e.DataRow("a20")
                                                                                e.DataRow("s20") = e.DataRow("s19") - e.DataRow("a20")
                                                                                If e.DataRow("s20") <> 0 And e.DataRow("n") >= 21 Then
                                                                                    e.DataRow("z21") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                    e.DataRow("a21") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 20 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                    e.DataRow("i21") = e.DataRow("z21")-e.DataRow("a21")
                                                                                    e.DataRow("s21") = e.DataRow("s20")-e.DataRow("a21")
                                                                                    If e.DataRow("s21") <> 0 And e.DataRow("n") >= 22 Then
                                                                                        e.DataRow("z22") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                        e.DataRow("a22") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 21 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                        e.DataRow("s22") = e.DataRow("s21")-e.DataRow("a22")
                                                                                        If e.DataRow("s22") <> 0 And e.DataRow("n") >= 23 Then
                                                                                            e.DataRow("z23") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                            e.DataRow("a23") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 22 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                            e.DataRow("i23") = e.DataRow("z23")-e.DataRow("a23")
                                                                                            e.DataRow("s23") = e.DataRow("s22")-e.DataRow("a23")
                                                                                            If e.DataRow("s23") <> 0 And e.DataRow("n") >= 24 Then
                                                                                                e.DataRow("z24") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1 ) ^ e.DataRow("n") -1)
                                                                                                e.DataRow("a24") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 23 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                e.DataRow("i24") = e.DataRow("z24")-e.DataRow("a24")
                                                                                                e.DataRow("s24") = e.DataRow("s23")-e.DataRow("a24")
                                                                                                If e.DataRow("s24") <> 0 And e.DataRow("n") >= 25 Then
                                                                                                    e.DataRow("z25") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                    e.DataRow("a25") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 24 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                    e.DataRow("i25") = e.DataRow("z25")-e.DataRow("a25")
                                                                                                    e.DataRow("s25") = e.DataRow("s24")-e.DataRow("a25")
                                                                                                    If e.DataRow("s25") <> 0 And e.DataRow("n") >= 26 Then
                                                                                                        e.DataRow("z26") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                        e.DataRow("a26") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 25 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                        e.DataRow("i26") = e.DataRow("z26")-e.DataRow("a26")
                                                                                                        e.DataRow("s26") = e.DataRow("s25")-e.DataRow("a26")
                                                                                                        If e.DataRow("s26") <> 0 And e.DataRow("n") >= 27 Then
                                                                                                            e.DataRow("z27") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                            e.DataRow("a27") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 26 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                            e.DataRow("i27") = e.DataRow("z27")-e.DataRow("a27")
                                                                                                            e.DataRow("s27") = e.DataRow("s26")-e.DataRow("a27")
                                                                                                            If e.DataRow("s27") <>  0 And e.DataRow("n") >= 28 Then
                                                                                                                e.DataRow("z28") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/ 100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1 )
                                                                                                                e.DataRow("a28") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/ 100)^ 27 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                e.DataRow("i28") = e.DataRow("z28")-e.DataRow("a28")
                                                                                                                e.DataRow("s28") = e.DataRow("s27")-e.DataRow("a28")
                                                                                                                If e.DataRow("s28") <> 0 And e.DataRow("n") >= 29 Then
                                                                                                                    e.DataRow("z29") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1 ) ^ e.DataRow("n") -1)
                                                                                                                    e.DataRow("a29") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 28 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                    e.DataRow("i29") = e.DataRow("z29")-e.DataRow("a29")
                                                                                                                    e.DataRow("s29") = e.DataRow("s28")-e.DataRow("a29")
                                                                                                                    If e.DataRow("s29") <> 0 And e.DataRow("n") >= 30 Then
                                                                                                                        e.DataRow("z30") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                        e.DataRow("a30") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 29 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                        e.DataRow("i30") = e.DataRow("z30")-e.DataRow("a30")
                                                                                                                        e.DataRow("s30") = e.DataRow("s29")-e.DataRow("a30")
                                                                                                                        If e.DataRow("s30") <> 0 And e.DataRow("n") >= 31 Then
                                                                                                                            e.DataRow("z31") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                            e.DataRow("a31") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 30 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                            e.DataRow("i31") = e.DataRow("z31")-e.DataRow("a31")
                                                                                                                            e.DataRow("s31") = e.DataRow("s30")-e.DataRow("a31")
                                                                                                                            If e.DataRow("s31") <> 0 And e.DataRow("n") >= 32 Then
                                                                                                                                e.DataRow("z32") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                                e.DataRow("a32") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 31 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                                e.DataRow("i32") = e.DataRow("z32")-e.DataRow("a32")
                                                                                                                                e.DataRow("s32") = e.DataRow("s31")-e.DataRow("a32")
                                                                                                                                If e.DataRow("s32") <> 0 And e.DataRow("n") >= 33 Then
                                                                                                                                    e.DataRow("z33") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                                    e.DataRow("a33") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 32 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                                    e.DataRow("i33") = e.DataRow("z33")-e.DataRow("a33")
                                                                                                                                    e.DataRow("s33") = e.DataRow("s32")-e.DataRow("a33")
                                                                                                                                    If e.DataRow("s33") <> 0 And e.DataRow("n") >= 34 Then
                                                                                                                                        e.DataRow("z34") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                                        e.DataRow("a34") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 33 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                                        e.DataRow("i34") = e.DataRow("z34")-e.DataRow("a34")
                                                                                                                                        e.DataRow("s34") = e.DataRow("s33")-e.DataRow("a34")
                                                                                                                                        If e.DataRow("s34") <> 0 And e.DataRow("n") >= 35 Then
                                                                                                                                            e.DataRow("z35") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                                            e.DataRow("a35") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 34 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                                            e.DataRow("i35") = e.DataRow("z35")-e.DataRow("a35")
                                                                                                                                            e.DataRow("s35") = e.DataRow("s34")-e.DataRow("a35")
                                                                                                                                            If e.DataRow("s35") <> 0 And e.DataRow("n") >= 36 Then
                                                                                                                                                e.DataRow("z36") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                                                                                                                                                e.DataRow("a36") = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 35 / ((e.DataRow("i")/100 + 1 ) ^ e.DataRow("n") -1)
                                                                                                                                                e.DataRow("i36") = e.DataRow("z36")-e.DataRow("a36")
                                                                                                                                                e.DataRow("s36") = e.DataRow("s35")-e.DataRow("a36")
                                                                                                                                            End If
                                                                                                                                        End If
                                                                                                                                    End If
                                                                                                                                End If
                                                                                                                            End If
                                                                                                                        End If
                                                                                                                    End If
                                                                                                                End If
                                                                                                            End If
                                                                                                        End If
                                                                                                    End If
                                                                                                End If
                                                                                            End If
                                                                                        End If
                                                                                    End If
                                                                                End If
                                                                            End If
                                                                        End If
                                                                    End If
                                                                End If
                                                            End If
                                                        End If
                                                    End If
                                                End If
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End If
End If


--  作者:有点蓝
--  发布时间:2017/7/6 16:13:00
--  
图片点击可在新窗口打开查看
你还是上个例子看看数据,再考虑有没有其它优化的方法

--  作者:有点甜
--  发布时间:2017/7/6 16:22:00
--  

 汗,代码不是这样写的。

 

写成循环,可以简化代码。

 

同时,要判断列名,不然死循环

 

Select Case e.DataCol.name
    Case "i", "n", "A"
        For i As Integer = 1 To 36
            If i <= e.DataRow("n")  Then
                e.DataRow("z" & i) = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                e.DataRow("a" & i) = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 0 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                e.DataRow("i" & i) = e.DataRow("z" & i)-e.DataRow("a" & i)
                e.DataRow("s" & i) = iif(i=1,e.DataRow("A"),e.DataRow("s" & i-1))-e.DataRow("a" & i)
            Else
                e.DataRow("z" & i) = Nothing
                e.DataRow("a" & i) = Nothing
                e.DataRow("i" & i) = Nothing
                e.DataRow("s" & i) = Nothing
               
            End If
        Next     
End Select


--  作者:1452565001
--  发布时间:2017/7/6 16:34:00
--  
好的,我去试试 谢谢
--  作者:1452565001
--  发布时间:2017/7/6 16:49:00
--  
以下是引用有点甜在2017/7/6 16:22:00的发言:

 汗,代码不是这样写的。

 

写成循环,可以简化代码。

 

同时,要判断列名,不然死循环

 

Select Case e.DataCol.name
    Case "i", "n", "A"
        For i As Integer = 1 To 36
            If i <= e.DataRow("n")  Then
                e.DataRow("z" & i) = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^e.DataRow("n")/ ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                e.DataRow("a" & i) = e.DataRow("A") * e.DataRow("i")/100 * (1 + e.DataRow("i")/100)^ 0 / ((e.DataRow("i")/100 + 1) ^ e.DataRow("n") -1)
                e.DataRow("i" & i) = e.DataRow("z" & i)-e.DataRow("a" & i)
                e.DataRow("s" & i) = iif(i=1,e.DataRow("A"),e.DataRow("s" & i-1))-e.DataRow("a" & i)
            Else
                e.DataRow("z" & i) = Nothing
                e.DataRow("a" & i) = Nothing
                e.DataRow("i" & i) = Nothing
                e.DataRow("s" & i) = Nothing
               
            End If
        Next     
End Select

我换成了您的代码 但是当n大于20之后还是会出现项目突然关闭的情况。


--  作者:有点甜
--  发布时间:2017/7/6 16:52:00
--  

DataColChanged其余代码删除,单独留5楼的代码,也有问题?

 

如果还有问题,具体实例发上来测试。


--  作者:1452565001
--  发布时间:2017/7/6 17:22:00
--  
换了台电脑之后可以了。。。谢谢老师!