Foxtable(狐表)用户栏目专家坐堂 → [求助]采用代码进行计算数据时导致项目直接关闭的问题


  共有2499人关注过本帖树形打印复制链接

主题:[求助]采用代码进行计算数据时导致项目直接关闭的问题

美女呀,离线,留言给我吧!
1452565001
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:54 积分:486 威望:0 精华:0 注册:2017/6/7 16:59:00
[求助]采用代码进行计算数据时导致项目直接关闭的问题  发帖心情 Post By: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


 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:111419 积分:567171 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2017/7/6 16:13:00 [只看该作者]

图片点击可在新窗口打开查看
你还是上个例子看看数据,再考虑有没有其它优化的方法

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:54 积分:486 威望:0 精华:0 注册:2017/6/7 16:59:00
  发帖心情 Post By:2017/7/6 16:34:00 [只看该作者]

好的,我去试试 谢谢

 回到顶部
美女呀,离线,留言给我吧!
1452565001
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:54 积分:486 威望:0 精华:0 注册:2017/6/7 16:59:00
  发帖心情 Post By: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之后还是会出现项目突然关闭的情况。


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/7/6 16:52:00 [只看该作者]

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

 

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


 回到顶部
美女呀,离线,留言给我吧!
1452565001
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:54 积分:486 威望:0 精华:0 注册:2017/6/7 16:59:00
  发帖心情 Post By:2017/7/6 17:22:00 [只看该作者]

换了台电脑之后可以了。。。谢谢老师!

 回到顶部