如何解决“集合索引必须在1到集合大小的范围内”? [英] how to solve "Collection index must be in the range 1 to the size of the collection"?

查看:197
本文介绍了如何解决“集合索引必须在1到集合大小的范围内”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行代码并经过两个表单后,我从一个列表框中选择项目,从另一个列表框中选择另一个项目,然后单击land按钮。之后我收到一条错误,说收集索引必须在1到集合大小的范围内。



when i run the code and after going through two forms i select item from one list box and another item from another listbox and click on land button. after that i get an error saying "Collection index must be in the range 1 to the size of the collection."

Private Sub btn_land_plane_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_land_plane.Click<br />
<br />
        Dim runwayindexno As Integer<br />
        Dim runwayfrmselected As Form<br />
        runwayindexno = lst_runways.SelectedIndex<br />
        runwayfrmselected = runway(runwayindexno)<br />
<br />
    End Sub




突出显示[== runway(runwayindexno)]并显示错误。



我寻找的解决方案找不到与我的代码相关的解决方案。我不知道要包含多少代码

如果需要我可以发布。

如果您需要更多信息请咨询并且非常感谢任何帮助。


It highlight [==runway(runwayindexno)] and displays the error.

i have looked for the solution cant find one that relates to my code. i don't know how much code
to include if need i can post.
if you need any more information please ask and any help is much appreciated.

推荐答案

问题肯定在于VB.NET处理数组索引的方式。

显然,在.vb文件中必须有一个

The problem surely lies in the way VB.NET is handling array indices.
Obviously, in your .vb file there must be a
Option Base 1



指令。



这具有将数组从1索引到Count的效果。

ListBox 的SelectedIndex 返回介于0和(Count-1)之间的值(对应于 VB.NET中的Option Base 0 。



您有两种选择:

- 或者你设置选项基础0

- 或者你转换通过添加它获得的每个索引1



前者可能是最好的,因为这将导致一种一致性y你的应用程序中有数组索引。


directive.

This has the effect of indexing arrays from 1 to Count.
Whereas the SelectedIndex of a ListBox returns a value between 0 and (Count - 1) (which corresponds to Option Base 0 in VB.NET).

You then have two alternatives :
- OR you set Option Base 0
- OR you convert every index obtained by adding it 1

The former is probably the best one, as this will lead to a kind of consistency with array indices in your application.


这是因为 runwayindexno 超出了数组 runway的索引。我想你正试图从列表框中检索索引并执行一些操作。
This occurs because runwayindexno is outside the index of the array runway. I think you're trying to do retrieve index from a list box and perform some operation.


这篇关于如何解决“集合索引必须在1到集合大小的范围内”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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