troubleshooting Question

Index was out of range

Avatar of Sreekanth_Nagabandi
Sreekanth_Nagabandi asked on
Visual Basic.NET
3 Comments1 Solution312 ViewsLast Modified:

I am getting an error message at the following line. Please look at the following line in the below method and resolve the error.

AlarmView.Nodes.Item(1).Text = CInt(txt_max_value.Text)

Error Message :- Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Protected Sub but_update_condition_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles but_update_condition.Click

        Dim sel_node As String
        Dim con_id As Integer
        Dim min_value As Integer
        Dim max_value As Integer
        Dim signal_id As String
        Dim alarm_field_condition_id As Integer

        ' AlarmId = 110
        AlarmId = Session("AlarmId")
        'Session("AlarmId") = AlarmId

        sel_node = AlarmView.SelectedValue

        If Len(sel_node) > 3 And sel_node.Substring(0, 3) = "CON" Then
            con_id = sel_node.Substring(3)
            Exit Sub
        End If

        'Dim sql As String

        'sql = "update v_alarm_definition_list "

        min_value = CInt(txt_min_value.Text)
        max_value = CInt(txt_max_value.Text)
        signal_id = " & ddl_signal_name.SelectedValue & "

        Dim include_min As String
        Dim include_max As String

        If ddl_include_min.SelectedValue = "LT" Then
            include_min = "N"
            include_min = "Y"
        End If

        If ddl_include_max.SelectedValue = "LT" Then
            include_max = "N"
            include_max = "Y"
        End If

        include_min = " & include_min & "
        include_max = " & include_max & "
        alarm_field_condition_id = CInt(con_id)

        'sql = sql & "include_max = '" & include_max & "' "

        'sql = sql & " where alarm_field_condition_id = " & con_id

            AlarmView.Nodes.Item(0).Text = CInt(txt_min_value.Text)
            AlarmView.Nodes.Item(1).Text = CInt(txt_max_value.Text)
            AlarmView.Nodes.Item(4).Text = ddl_signal_name.SelectedValue

            ' Dim cmd As New SqlCommand(sql, Conn)

            ' Dim row_count = cmd.ExecuteNonQuery

        Catch ex As Exception

        End Try

    End Sub



Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros