以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 索引超出了数组界限 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=186983) |
-- 作者:edisontsui -- 发布时间:2023/6/13 8:05:00 -- 索引超出了数组界限 With e.Form.Controls("textbox1") Dim ctn1() As String = DataTables("出入库").SQLGetComboListString("物料编号", "[出入年月] = \'" & .Value & "\' and [来源] = \'" & "自做" & "\'").Split("|") \'msgbox("ctn1.length=" & ctn1.length) \'数据正确 For s1 As Integer = 0 To ctn1.length - 1 msgbox("s1=" & s1) \'这句会显示 s1 = 0, 然后出现“索引超出了数组界限”的提示 Dim ctn2() As String = DataTables("出入库").SQLGetComboListString("出入原因", "[出入年月] = \'" & .Value & "\' and [来源] = \'" & "自做" & "\' and [物料编号] = \'" & ctn1(s1 - 1) & "\'").Split("|") msgbox("ctn2.length=" & ctn2.length) 这句就不出来了。 For s2 As Integer = 0 To ctn2.length - 1 msgbox("s2=" & s2) Dim ctn3() As String = DataTables("出入库").SQLGetComboListString("不含税单价", "[出入年月] = \'" & .Value & "\' and [来源] = \'" & "自做" & "\' and [物料编号] = \'" & ctn1(s1 - 1) & "\' and [出入原因] = \'" & ctn2(s2 - 1) & "\'").Split("|") For s3 As Integer = 0 To ctn3.length - 1 msgbox("s3=" & s3) Dim qty1 As Single = Tables("出入库").Compute("sum(入库数量)", "出入年月 = \'" & .Value & "\' and 来源 = \'" & "自做" & "\' and 物料编号 = \'" & ctn1(s1 - 1) & "\' and 出入原因 = \'" & ctn2(s2 - 1) & "\' and 不含税单价 = \'" & ctn3(s3 - 1) & "\' ") Dim qty2 As Single = Tables("出入库").Compute("sum(出库数量)", "出入年月 = \'" & .Value & "\' and 来源 = \'" & "自做" & "\' and 物料编号 = \'" & ctn1(s1 - 1) & "\' and 出入原因 = \'" & ctn2(s2 - 1) & "\' and 不含税单价 = \'" & ctn3(s3 - 1) & "\' ") Dim dr1 As DataRow = DataTables("库存明细").Find("出入年月 = \'" & .Value & "\' and 物料编号 = \'" & ctn1(s1 - 1) & "\' and 出入原因 = \'" & ctn2(s2 - 1) & "\' and 不含税单价 = \'" & ctn3(s3 - 1) & "\'") If dr1 IsNot Nothing Then Else Dim dr2 As DataRow = DataTables("库存明细").AddNew() dr2("出入年月") = .Value dr2("物料编号") = ctn1(s1 - 1) dr2("出入原因") = ctn2(s2 - 1) dr2("入库数量") = qty1 End If Next Next Next end with 老师好。请看上面代码里面红色部分我的说明。我想问的问题是,难道是蓝色那句有问题吗?如果是,要怎样修改?谢谢。
|
-- 作者:有点蓝 -- 发布时间:2023/6/13 8:28:00 -- s1 = 0,那么s1 - 1就是-1,索引是不会有-1 的,所以【ctn1(s1 - 1)】就出错了 |
-- 作者:edisontsui -- 发布时间:2023/6/13 11:54:00 -- 谢谢您的提醒。还有: Dim ctn3() As String = DataTables("出入库").SQLGetComboListString("不含税单价", "[出入年月] = \'" & .Value & "\' and [来源] = \'" & "自做" & "\' and [物料编号] = \'" & ctn1(s1 - 1) & "\' and [出入原因] = \'" & ctn2(s2 - 1) & "\'").Split("|") 这句代码是对“不含税单价”提取字符串,但是碰到不含税单价为0时就无法提取数据(就是跳过去了,当这些记录不存在)。请问有什么办法解决吗?谢谢。
|
-- 作者:有点蓝 -- 发布时间:2023/6/13 12:06:00 -- 单价为0其实就是没有数据,要来有什么用?这种情况如果需要自己最后补一个为0 的值不就行了 |