且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Vb.net:索引超出范围必须是非负且小于集合参数索引的大小

更新时间:2022-04-12 22:18:19

如果没有您的数据,我们无法解决您的问题 - 我们无法访问您的数据!



所以,这取决于你。

幸运的是,你有一个工具可以帮助你找到正在发生的事情:调试器。快速谷歌Visual Studio和调试器应该为您提供所需的信息。



在函数的第一行放置一个断点,并运行你的代码通过调试器。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。



对不起,但我们不能为你做到这一点 - 时间让你学习一门新的(非常非常有用的)技能:调试!
Without your data, we can't fix your problem - and we have no access to your data!

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. A quick Google for "Visual Studio" and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!


引用:

Vb.net:索引超出范围必须是非负且小于集合参数索引的大小

Vb.net: index was out of range must be nonnegative and less than the size of the collection parameter index



首先,当你寻求帮助时,告诉错误在哪里是个好主意。否则,我们只能猜测。

错误正是消息的说法。

在某个地方,你有一个数组或集合,你试图访问一个没有的位置存在。***的方法是使用调试器并检查变量以查看它出错的地方。



您的代码行为不符合您的预期,或者您不理解为什么!



有一个几乎通用的解决方案:一步一步地在调试器上运行你的代码,检查变量。

调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它不知道您的代码应该做什么,它不要找不到错误,只是通过告诉你发生了什么来帮助你。当代码没有达到预期的效果时,你就接近了一个错误。

要查看你的代码在做什么:只需设置断点并查看代码是否正常运行,调试器允许你执行第1行第1行并在执行时检查变量

调试器 - ***,免费的百科全书 [ ^ ]



掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - *** [ ^ ]



Visual Basic / Visual Studio视频教程 - 基本调试 - *** [ ^ ]

初学者的Visual Basic .NET编程 - 断点和调试工具 [ ^ ]



调试器这里只是向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。


First of all, when you ask for help, it is a nice idea to tell where is the error. Otherwise, we can only guess.
The error is exactly what says the message.
Somewhere, you have an array or collection and you try to access a position that does not exist. The best move is to use the debugger and inspect variables to see where it goes wrong.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute
Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - ***[^]

Visual Basic / Visual Studio Video Tutorial - Basic Debugging - ***[^]
Visual Basic .NET programming for Beginners - Breakpoints and Debugging Tools[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.