IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled
Go Back  Xtreme Visual Basic Talk > > > IndexOutOfRangeException was unhandled


Reply
 
Thread Tools Display Modes
  #1  
Old 02-12-2013, 10:48 AM
Solar Dragon Solar Dragon is offline
Newcomer
 
Join Date: Feb 2013
Posts: 11
Default IndexOutOfRangeException was unhandled


Hello,
I have been getting this error and I have no idea why. It keeps saying that there is no row at position 1 even though I have 4 rows in my table.

My code is here:
Code:
Private Sub Populate()
        Dim ResultsRow As Integer
        Dim QuizRow As Integer

        ResultsRow = CInt(PupilIDTxt.Text)
        ResultsManager.Position = ResultsRow
        QuizRow = CInt(QuizIDTxt.Text)
        QuizManager.Position = QuizRow

        Try
            GradeTxt.Text = CStr(ResultsTable.Rows(ResultsRow).Item("Grade"))
        Catch ex As Exception
            If ResultsTable.Rows(ResultsRow).Item("Grade").ToString <> "*" Then
                GradeTxt.Text = ""
            End If
        End Try
            Try
                ResultTxt.Text = CStr(ResultsTable.Rows(ResultsRow).Item("Result"))
            Catch ex As Exception
                If ResultsTable.Rows(ResultsRow).Item("Result").ToString <> "*" Then
                    ResultTxt.Text = ""
                End If
            End Try

        Try
            NameTxt.Text = CStr(ResultsTable.Rows(ResultsRow).Item("QuizName"))
        Catch ex As Exception
            If QuizTable.Rows(QuizRow).Item("QuizName").ToString <> "*" Then
                NameTxt.Text = ""
            End If
        End Try
            Try
                TopicTxt.Text = CStr(QuizTable.Rows(QuizRow).Item("QuizTopic"))
            Catch ex As Exception
                If QuizTable.Rows(QuizRow).Item("QuizTopic").ToString <> "*" Then
                    TopicTxt.Text = ""
                End If
            End Try
            Try
                DifficultyTxt.Text = CStr(QuizTable.Rows(QuizRow).Item("Difficulty"))
            Catch ex As Exception
                If QuizTable.Rows(QuizRow).Item("Difficulty").ToString <> "*" Then
                    DifficultyTxt.Text = ""
                End If
            End Try

    End Sub
It is happening on this line:

Code:
  If ResultsTable.Rows(ResultsRow).Item("Grade").ToString <> "*" Then
Thanks in advance
Reply With Quote
  #2  
Old 02-13-2013, 05:31 AM
DrPunk's Avatar
DrPunkIndexOutOfRangeException was unhandled DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

It's difficult to accept that VB is lying to you. I'd like to think that it tried its hardest to find the row at the position it was told.

How have you determined you have 4 rows? Are you sure those 4 rows are in ResultsTable? You can always messagebox out the ResultsTable.Rows.Count to the screen to see how many there are for yourself.
__________________
There are no computers in heaven!

Last edited by DrPunk; 02-13-2013 at 05:44 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled
 
IndexOutOfRangeException was unhandled
IndexOutOfRangeException was unhandled
 
-->