0

I am studying form event for VB.NET

My program is loading and setting some of date on the VB.NET form.

I suddenly get System.IndexOutOfRangeException when software switch check box to true

for example, I am using control and for loop to switch check box status I am using control method to looping and searching checkbox in the groupbox

For Each c As Control In GT.SET_MY.Controls
    If c.GetType Is GetType(CheckBox) Then
        Dim sc As CheckBox = DirectCast(c, CheckBox)
        If BW_List(BW_INDEX).Trim = "Y" Then
            **sc.Checked = CB.T** ' **ERR POINT**
            Tracker = sc.Text
        Else
            sc.Checked = CB.F
        End If
        BW_INDEX -= 1
    End If
Next

When program is set checkbox to false like " sc.Checked = CB.F". It doesn't have any error

However, when program is set checkbox to true(sc.Checked = CB.T), it returns to System.IndexOutOfRangeException

I am not clearly sure why this happen...

error message is

A first chance exception of type 'System.IndexOutOfRangeException' occurred in Myproject.exe

Step into: Stepping over non-user code 'System.Windows.Forms.Control.WmShowWindow'

Step into: Stepping over non-user code 'System.Windows.Forms.NativeWindow.DebuggableCallback'

Step into: Stepping over non-user code 'System.Windows.Forms.Control.SetVisibleCore'

Step into: Stepping over non-user code 'System.Windows.Forms.Form.SetVisibleCore'

does anybody know why this happen ?

OK

I found major problem of this error

When Software is automatically check or uncheck, it randomly triggers some events in the software and it become cause of error.

Bob Ma
  • 197
  • 5
  • 11
  • 22
  • What is CB? What are the values of CB.F & CB.T? – User999999 Aug 04 '15 at 08:11
  • @ User999999 thanks for your helping CB.F and CB.T is checking or un checking checkbox – Bob Ma Aug 04 '15 at 21:34
  • BW_List(BW_INDEX) is a very dangerous expression. The *next* checkbox will trigger this exception since -1 is not a valid index. – Hans Passant Aug 04 '15 at 21:55
  • @ Hans Passant oh you are right!!! I already fixed the problems, but it can be cause of another problem. i will change it right now. Thanks for your help :) – Bob Ma Aug 04 '15 at 22:35

0 Answers0