By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,265 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

An error occurred creating the form... the error is: Index was out of range.

P: 2
Hello All,

While trying to open a form I get the following error:

An error occurred creating the form. See Exception.InnerException for details. The error is: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Previously the form loaded flawlesly. I made several small changes to subs contained in the form, and after that the problem appeared. These changes included some changes in the constructor.

I've tried to track down the problem simply by adding message boxes near potential problem areas, and it seems that the exception is thrown before the constructor is even run. The error message baffles me, since I'm not knowingly using any parameters, and the routine opening the form doesn't refer to any arrays (or any other variables).

Here is the part of the source code that the error message refers to:

Expand|Select|Wrap|Line Numbers
  1. Private Sub SugNewTagsBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SugNewTagsBtn.Click
  2.         SugNewTagsForm.Show()
  3.     End Sub
I would really appreciate any advice you might have, since a cursory googling didn't yield any similar cases (which is weird, usually someone has already met and defeated the hurdles I'm faced with... I'm not that advanced a programmer)
Sep 11 '10 #1
Share this Question
Share on Google+
1 Reply

P: 2
Okay, I found the problem. I had placed a function call in the initialising sub that handles MyBase.Load for the form, and this function had an internal reference to a table which reads it's values from a textbox placed on the form. As this textbox has default content (set in MS Visual Basic Express 2010 editor), I made the mistake of presuming it has content when MyBase.Load takes place. Since it has no content, the array will have no entries and thus referring to the arrays' index 0 causes the error.

What really confused me was that the error message referred to another form entirely (the form which opens the erroneous form), and that the initialising sub never ran.

I hope this monologue proves helpful to some other amateur fidling around with VB. :)
Sep 12 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.