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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sven Willgren
    New Member
    • Sep 2010
    • 2

    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.Inner Exception 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:

    Code:
    Private Sub SugNewTagsBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SugNewTagsBtn.Click
            SugNewTagsForm.Show()
        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)
  • Sven Willgren
    New Member
    • Sep 2010
    • 2

    #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. :)

    Comment

    Working...