以文本方式查看主题

-  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=162982)

--  作者:gaolei
--  发布时间:2021/4/19 15:20:00
--  索引超出范围
If e.DataCol.name = "是否参与记账" And e.DataRow("是否参与记账") = True And E.DataRow("收款摘要") = ""
      MessageBox.Show("您好!您的收款摘要很可能为空白,请补充完整吧")
End If
Dim a As Integer
If e.DataCol.name = "是否参与记账" And e.DataRow("是否参与记账") = True
    Dim DRS  As List(OF DataRow)
    DRS = DataTables("续时账模板").Select("[记账参数匹配列] =\'"& E.DataRow("收款摘要") &"\'")
    A=DRS.Count
For I As Integer = 1 To A
    Tables("销售续时账").AddNew(1)
    Tables("销售续时账").current("记账日期") = e.DataRow("日期")
     Tables("销售续时账").current("摘要") = e.DataRow("收款摘要") & e.DataRow("客户姓名")
     Tables("销售续时账").current("科目") = drs(I)("科目")
MessageBox.Show(1)
   If drs(I)("方向") = "借" Then
        Tables("销售续时账").current("借方金额") = e.DataRow("收款金额")
        Tables("销售续时账").current("贷方金额") = e.DataRow("收款金额")-e.DataRow("收款金额")
        Else 
        Tables("销售续时账").current("借方金额") = e.DataRow("收款金额") - e.DataRow("收款金额")
        Tables("销售续时账").current("贷方金额") = e.DataRow("收款金额")
    End If
MessageBox.Show(2)
   Tables("销售续时账").current("核算项目1") = drs(I)("核算项目1")
   Tables("销售续时账").current("核算项目2") = drs(I)("核算项目2")
    Tables("销售续时账").current("核算项目3") = drs(I)("核算项目3")
MessageBox.Show(3)
Next
End If

各位老师,下午好,我三条调试信息都能正常显示,但最后却总是蹦出来:

错误所在事件:表,收款台账_收银员,DataColChanged
详细错误信息:
调用的目标发生了异常。
索引超出范围。必须为非负值并小于集合大小。
参数名: index

我检查了几遍感觉我写的代码是没有问题的,是不是系统有bug啊






--  作者:有点蓝
--  发布时间:2021/4/19 15:36:00
--  
For I As Integer = 1 To A

改为

For I As Integer = 0 To A - 1

集合索引是从0开始的,不是从1开始

--  作者:gaolei
--  发布时间:2021/4/19 15:43:00
--  
嗷嗷嗷,吐血啊,原来错在这,我在这找了半天图片点击可在新窗口打开查看