问题描述
当我运行代码并经过两个表单后,我从一个列表框中选择项目,从另一个列表框中选择另一个项目,然后单击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.
推荐答案
Option Base 1
指令。
这具有将数组从1索引到Count的效果。
而
返回介于0和(Count-1)之间的值(对应于 VB.NET中的Option Base 0 。 ListBox
的SelectedIndex
您有两种选择:
- 或者你设置选项基础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.
这篇关于如何解决“集合索引必须在1到集合大小的范围内”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!