指数超出范围。必须是非负数且小于集合的大小。参数名称:vb.net中的索引 [英] Index was out of range. Must be non-negative and less then size of the collection. Parameter name: index in vb.net

查看:161
本文介绍了指数超出范围。必须是非负数且小于集合的大小。参数名称:vb.net中的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,



我在下面的代码中遇到上述错误。错误行也会突出显示:

Hello All,

I am getting the above error in the following piece of code. The row of error is also highlighted:

 	Dim Debittotal As Integer = 0
        Dim Credittotal As Integer = 0

        If grdDebit.RowCount > 1 Then
            For index As Integer = 0 To grdDebit.RowCount - 1
*****                Debittotal += Convert.ToDecimal(grdDebit.Rows(index).Cells(2).Value)
            Next
        End If

        If grdCredit.RowCount > 1 Then
            For index As Integer = 0 To grdCredit.RowCount - 1
                Credittotal += Convert.ToDecimal(grdCredit.Rows(index).Cells(2).Value)
            Next
        End If


        Dim NewfnBalance As Integer = Debittotal - Credittotal

提前致谢。

推荐答案

这告诉您没有三个Cell元素。如果我是你,我会在导致错误的行上设置一个断点,并查看 grdDebit.Rows(index)的值。我怀疑你所追求的价值是 Cells(1)
This is telling you that you don't have three Cell elements. If I were you, I would put a breakpoint on the line that's causing the error and take a look at the values of grdDebit.Rows(index). I suspect the value you are after is in Cells(1).


这篇关于指数超出范围。必须是非负数且小于集合的大小。参数名称:vb.net中的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆