469,357 Members | 1,629 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,357 developers. It's quick & easy.

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

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
1 6045
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.

Similar topics

16 posts views Thread by ES Kim | last post: by
reply views Thread by vareck.walla | last post: by
2 posts views Thread by SBlain | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.