i have this error when i display my program ?

' Created by SharpDevelop.
' User: s11088659
' Date: 5/28/2014
' Time: 11:26 AM
' To change this template use Tools | Options | Coding | Edit Standard Headers.
Public Partial Class MainForm
    Public Sub New()
        ' The Me.InitializeComponent call is required for Windows Forms designer support.

        ' TODO : Add constructor code after InitializeComponents
    End Sub

    private Sub DisplaybuttonClick(byval sender As Object,byval e As system.EventArgs)
        'Declare variable of array name and grade of student

        'Dim strNames() As String = {“Hova”, “Nemo”, “Zoc”, “Lucas”,“Phuket”, “Cindy”, “Marlin”, “Darla”, “Nigel”, “Cindrella”}
         Dim dblMarks() As Double = {32.5,88,90.5,67.5,65,77.5,85,78.5,89.5,90}
         Dim int As Integer
         Dim intotal As Integer
         Dim avg As Decimal

         For int = 0 To 11
            intotal = intotal + dblMarks(int)
         Next int

         avg = convert.ToDecimal(intotal/dblMarks.Length)
         displaylabel.text = " Average: " & avg.tostring("N1")

    End Sub

End Class

Index was outside the bounds of the array.what should i do to solve the error?

4 Years
Discussion Span
Last Post by Bendez Thyna

You have only added 10 elements to the array dblMarks but you are stepping up to 11 in your loop. No position 11 exists in the array.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.