以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  超出索引范围的问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=34719)

--  作者:东坡一剑
--  发布时间:2013/6/13 21:53:00
--  超出索引范围的问题

在表“库存透视及取货方案”的“出库数量”中输入“20”,在表“取货明细”中能正常显示取货数量和箱号,可是输入“21”或"22"就会报错。问题出在表“库存透视及取货方案”datacolchanged事件代码的“ Case "取货方案_1","产品条码" " 中,我已标明了位置。

请专家帮帮忙,指出问题在什么地方。先谢了!

 下载信息  [文件大小:   下载次数: ]
点击浏览该文件:例子.foxdb


--  作者:程兴刚
--  发布时间:2013/6/13 22:55:00
--  

直接贴代码!


--  作者:don
--  发布时间:2013/6/13 23:27:00
--  
沒詳細看,不過有個錯誤很明顯:同一SELECT CASE下, 下面的CASE "產品條碼"重疊了,則只會執行執行第一個 Case "产品条码"!
後面的"产品条码"變化時是不會執行的

Case "产品条码"
\'
Case "出库数量","产品条码"
\'
Case "取货方案_1","产品条码"
\'
Case "取货方案_2","产品条码" 
\'
Case "取货方案_3","产品条码"  

--  作者:东坡一剑
--  发布时间:2013/6/14 16:17:00
--  

    Case "取货方案_1","产品条码"                                                                             \'错误代码起始
        Dim drs As List (Of DataRow)
        Dim dr As DataRow
        Dim dr1 As DataRow
        Dim Int As Integer = e.DataRow("取货方案_1")
        Dim Int1 As Integer
        Dim filter As String = "库存_库房号 =\'1\'  And 产品条码 = \'" & e.DataRow("产品条码") & "\'"
        Dim id As String = "And [_identify] <> -1"
        If e.DataRow.IsNull("取货方案_1") = False Then
            Do While Int > 0
                drs = DataTables("库存表").Select(filter & id & "And 库存数量 >= " & Int)
                Int1 = Math.Abs(drs(0)("库存数量") - Int)
                For i As Integer = 1 To drs.count - 1
                    Int1 = Math.Min(Int1,Math.Abs(drs(i)("库存数量") - Int))
                Next
                dr = DataTables("库存表").Find(filter & id & "And 库存数量 = " & Int + Int1)
                If dr IsNot Nothing
                    dr1 = DataTables("取货明细").AddNew()
                    dr1("取货_数量") = Int
                    dr1("取货_箱号") = dr("库存_装箱号")
                    Int = 0
                Else
                    drs = DataTables("库存表").Select(filter & id & "And 库存数量 < " & Int)
                    Int1 =Int - drs(0)("库存数量")
                    For i As Integer = 1 To drs.count - 1
                        Int1 = Math.Min(Int1,Int-drs(i)("库存数量"))
                    Next
                    dr = DataTables("库存表").Find(filter &  id & " And 库存数量 = " & Int - Int1)
                    If dr IsNot Nothing Then
                        dr1 = DataTables("取货明细").AddNew()
                        dr1("取货_数量") = dr("库存数量")
                        dr1("取货_箱号") = dr("库存_装箱号")
                        Int = Int1                       
                        If id = "And [_identify] <> -1" Then
                            id = "And [_identify] <> " & dr("_identify")
                        Else
                            id = id & "And [_identify] <> " & dr("_identify")
                        End If
                    End If
                End If
            Loop
        End If  

 

那就有劳了!

 


--  作者:Bin
--  发布时间:2013/6/14 16:58:00
--  
Case "取货方案_1","产品条码"                                                                             \'错误代码起始
        Dim drs As List (Of DataRow)
        Dim dr As DataRow
        Dim dr1 As DataRow
        Dim Int As Integer = e.DataRow("取货方案_1")
        Dim Int1 As Integer
        Dim filter As String = "库存_库房号 =\'1\'  And 产品条码 = \'" & e.DataRow("产品条码") & "\'"
        Dim id As String = "And [_identify] <> -1"
        If e.DataRow.IsNull("取货方案_1") = False Then
            Do While Int > 0
                drs = DataTables("库存表").Select(filter & id & "And 库存数量 >= " & Int)
                Int1 = Math.Abs(drs(0)("库存数量") - Int)    如果Select出来的行数为0的话.你就无法获得第一行 那么就报错
                For i As Integer = 1 To drs.count - 1
                    Int1 = Math.Min(Int1,Math.Abs(drs(i)("库存数量") - Int))
                Next
                dr = DataTables("库存表").Find(filter & id & "And 库存数量 = " & Int + Int1)
                If dr IsNot Nothing
                    dr1 = DataTables("取货明细").AddNew()
                    dr1("取货_数量") = Int
                    dr1("取货_箱号") = dr("库存_装箱号")
                    Int = 0
                Else
                    drs = DataTables("库存表").Select(filter & id & "And 库存数量 < " & Int)
                    Int1 =Int - drs(0)("库存数量")
                    For i As Integer = 1 To drs.count - 1
                        Int1 = Math.Min(Int1,Int-drs(i)("库存数量"))
                    Next
                    dr = DataTables("库存表").Find(filter &  id & " And 库存数量 = " & Int - Int1)
                    If dr IsNot Nothing Then
                        dr1 = DataTables("取货明细").AddNew()
                        dr1("取货_数量") = dr("库存数量")
                        dr1("取货_箱号") = dr("库存_装箱号")
                        Int = Int1                        
                        If id = "And [_identify] <> -1" Then
                            id = "And [_identify] <> " & dr("_identify")
                        Else
                            id = id & "And [_identify] <> " & dr("_identify")
                        End If
                    End If
                End If
            Loop
        End If  
--  作者:东坡一剑
--  发布时间:2013/6/14 17:17:00
--  

那么,

是否加上

if drs.count > 0 then

判断一下就可以了?


--  作者:Bin
--  发布时间:2013/6/14 17:18:00
--  
判断一下 drs  是否为NOthing  只要不是空就说明肯定有至少一行  那么drs(0)就不会报错