以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助] 急  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=173952)

--  作者:sanny
--  发布时间:2021/12/23 21:42:00
--  [求助] 急

老师,程序运行时出现如下错误,以前都没有问题的,是什么问题 ?

.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2021.5.29.1
错误所在事件:自定义函数,sumChild
详细错误信息:
调用的目标发生了异常。
索引超出了数组界限。



--  作者:有点蓝
--  发布时间:2021/12/23 21:46:00
--  
函数代码发上来看看呀。提示索引有问题,一般是数据问题引起的
--  作者:sanny
--  发布时间:2021/12/23 22:00:00
--  
老师,如下,用了很长时间了,以前都没有问题,就这几天出现了。

Dim pn As String = args(0)
Dim qty As String = args(1)
Dim idx As Decimal = args(8)
Dim dic1 = vars("dic1")
Dim dic2 = vars("dic2")
\'Dim dic3 = vars("dic3")
Dim dic4 = vars("dic4")
Dim m1 As Decimal = args(9)
For Each dr As DataRow In  DataTables("BOM").Select("FNumber=\'" & pn & "\'")
    Dim ndr As DataRow = DataTables("物料需求").AddNew
    ndr("PartNo") = dr("PN")
    ndr("ETD") = args(3)
    ndr("批号") = args(4)
    ndr("company") = args(10)
    ndr("SOP") = args(11)
   ndr("BOM") = args(12)
ndr("ETA") = args(13)
ndr("CustomerPO") = args(14)
ndr("EndCustomer") = args(15)
ndr("ShippingTerms") = args(16)
ndr("Project") = args(17)
ndr("RequestETA") = args(18)
ndr("ConfirmedETA") = args(19)
ndr("GSS") = args(20)

   \' ndr("PartDesc") = dr("FName1")
    ndr("Demand") = dr("FQty") * qty
    ndr("层次") = "第" & idx & "层"
    Dim mq As Decimal = m1 * dr("FQty")
    Dim m2 As Decimal = args(6)+  args(7) - qty
    Dim flag = args(5) \' And m1 < 0
   
    If m1 <> 0 Then
    If dic1.ContainsKey(ndr("PartNo")) Then
        If m1 < 0 Then
            Dim aa As Decimal = mq*-1
            If dic1(ndr("PartNo")) >= aa Then
                ndr("Stock") = aa
ndr("库存剩余数量")= aa
            Else
                ndr("Stock") = dic1(ndr("PartNo"))
                ndr("库存剩余数量")= dic1(ndr("PartNo"))
            End If
            flag = False
        ElseIf dic1(ndr("PartNo")) > 0 Then
            ndr("Stock") = dic1(ndr("PartNo"))
ndr("库存剩余数量")= dic1(ndr("PartNo"))
        End If
        dic1(ndr("PartNo")) -= ndr("Stock")
ndr("库存剩余数量")= dic1(ndr("PartNo"))
        If dic1(ndr("PartNo"))< 0 Then dic1(ndr("PartNo")) = 0
    End If
    End If
    If dic2.ContainsKey(ndr("PartNo")) Then
        If flag = True And m1 > 0 Then
            Dim qty1 = ndr("Demand") - ndr("stock")
            If qty1 > 0 Then
                If dic2(ndr("PartNo")) >= qty1 Then
                    ndr("QC") = qty1
                    dic2(ndr("PartNo")) -= ndr("QC")
                    ndr("QC剩余数量") = dic2(ndr("PartNo"))
                ElseIf dic2(ndr("PartNo")) > 0 Then
                    ndr("QC") = dic2(ndr("PartNo"))
                    dic2(ndr("PartNo")) -= ndr("QC")
                    ndr("QC剩余数量") = dic2(ndr("PartNo"))
                End If
            End If
        ElseIf m1 < 0 Then
                Dim aa As Decimal = mq*-1
                If dic2(ndr("PartNo")) > aa - ndr("Stock")
                    ndr("QC") = aa - ndr("Stock")
 ndr("QC剩余数量") = dic2(ndr("PartNo"))
                Else
                    ndr("QC") = dic2(ndr("PartNo"))
 ndr("QC剩余数量") = dic2(ndr("PartNo"))
                End If
                dic2(ndr("PartNo")) -= ndr("QC")
 ndr("QC剩余数量") = dic2(ndr("PartNo"))
        End If
    End If
   
   
   
    \'If flag = True And m1 > 0 Then
       
       \' If dic3.ContainsKey(ndr("PartNo")) Then
        \'    Dim qty2 = ndr("Demand") - ndr("stock") - ndr("QC")
         \'   If qty2 > 0 Then
          \'      If dic3(ndr("PartNo")) >= qty2 Then
           \'         ndr("purchasingorder") = qty2
                   
                   
            \'        dic3(ndr("PartNo")) -= ndr("purchasingorder")
             \'   ElseIf dic3(ndr("PartNo")) > 0 Then
              \'      ndr("purchasingorder") = dic3(ndr("PartNo"))
               \'     dic3(ndr("PartNo")) -= ndr("purchasingorder")
               \' End If
           \' End If
           
       \' End If
    \'End If
   
    If flag  = True AndAlso m1 > 0 Then
        ndr("MissingQty") =  ndr("Stock")+ndr("QC") -ndr("Demand")+args(6)*dr("FQty")
    Else
        If m1 < 0 AndAlso mq*-1 > ndr("Stock")+ndr("QC")
            ndr("MissingQty") = mq + (ndr("Stock")+ndr("QC"))
        Else
            ndr("MissingQty") = 0
        End If
       
    End If
    If dic4.ContainsKey(ndr("PartNo")) = False Then
        dic4.add(ndr("PartNo"), ndr("MissingQty"))
    Else
        dic4(ndr("PartNo")) += ndr("MissingQty")
    End If
    ndr("SumMissing") = dic4(ndr("partno"))
    Functions.Execute("sumChild",dr("PN"),ndr("Demand"), args(2), args(3),args(4),flag, ndr("Stock"),ndr("QC"),idx+1,ndr("MissingQty"),args(10),args(11),args(12),args(13),args(14),args(15),args(16),args(17),args(18),args(19),args(20))
Next

--  作者:lihe60
--  发布时间:2021/12/23 22:40:00
--  
要发项目文件的
--  作者:有点蓝
--  发布时间:2021/12/23 22:43:00
--  
这个要靠自己去调试了,看是哪一行出错。可能原因

1、没有传入足够的参数数量,检查一下调用这个函数的地方
2、往"物料需求"表赋值的时候,触发了表事件,表事件有问题