Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

An unhandled exception of type 'System.IndexOutOfRangeException' occur

Status
Not open for further replies.

herbal

Programmer
Jul 10, 2003
36
US
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.windows.forms.dll

this is my error. It seems to me that this error originated when I added sorting to my datagrid with the following code:

With DsMembers.Members
.DefaultView.RowFilter = "TDL = '" + tdl + "'"
If .DefaultView.Count = 0 Then
'do something
End if
Try
dgrOutput.DataSource = .DefaultView
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End With

It seems to run through the code and then at the end throws the error at Line 3 which is the "Public Class Form1" line. I can't figure this out. Any help is greatly appreciated!!!
 
What do you mean 'at line 3 which is the "Public Class Form1" line'? You haven't shown this code here.

Durkin
 
I mean that I have no clue where the error is being thrown from since the error code says the error is at line 3. Line 3 is like the main code for the form.

dunno....I'm lost...
 
Step through the code in debug and you should be able to tell where it is being thrown. Otherwise use Debug.write() after each line around where you think the error is happening and view the output.

Durkin
 
Unfortunately, thats part of the problem. I really don't know where to begin. Like I said, the error didn't occur til I added the filter code, but I don't see anything that requires an index. So, I'm not sure where the error is coming from. Another unfortunate problem is that while I've got a pretty good grasp on making most code work, I am new to VB and still have no clue about the debugging process in the MDE. For instance, what does debug.writeline do? Messagebox?

Thanks for the reply!
Herbal
 
Debug.write will write to the output window. You can open this from the View -> Other Windows menu.
Regarding this error, it happens when you try to access an element in an array which doesn't exist. Like if you try to get the fifth element in an array who's length is only four.
As to debugging, here's an article from Microsoft:

Durkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top