Answered stack overflow again

paulthepaddy

Well-known member
Joined
Apr 9, 2011
Messages
222
Location
UK
Programming Experience
Beginner
sorry i cant figure it out now...
An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll
it also says make sure you do not have infinate loop or infinate recursion
il give all code in order that they are executed in
Check the chechbox and it disables all irelevent stuff and populates the combobox

VB.NET:
 Private Sub CheckBox_Spray_CheckedChanged(ByVal sender As  System.Object, ByVal e As System.EventArgs) Handles  CheckBox_Spray.CheckedChanged
        If Me.CheckBox_Spray.Checked = True Then
            Me.ComboBox_Spray.Enabled = True
            Me.ComboBox_SSR.Enabled = False
            Me.CheckBox_SSR.Checked = False
            Me.ComboBox_fiber.Enabled = False
            Me.CheckBox_Fiber.Checked = False
            Me.ComboBox_Aroma.Enabled = False
            Me.CheckBox_Aroma.Checked = False
            Me.ComboBox_Glass.Enabled = False
            Me.CheckBox_Glass.Checked = False
            Me.CheckBox_Walk.Visible = False
            Me.Damage_List.Items.Clear()
            Call Spray_list()
        End If
    End Sub
here is the Spray_List sub
VB.NET:
 Private Sub Spray_list()
        Call Clear_List()'it doesn't overflow here
        Me.Damage_List.Items.Add("Front O/S Bumper Corner")
        Me.Damage_List.Items.Add("Front N/S Bumper Corner")
        Me.Damage_List.Items.Add("Front Bumper Centre")
        Me.Damage_List.Items.Add("Rear O/S Bumper Corner")
        Me.Damage_List.Items.Add("Rear N/S Bumper Corner")
        Me.Damage_List.Items.Add("Rear Bumper Centre")
        Me.Damage_List.Items.Add("Front O/S Wing")
        Me.Damage_List.Items.Add("Front N/S Wing")
        Me.Damage_List.Items.Add("Rear O/S Quarter Panel")
        Me.Damage_List.Items.Add("Rear N/S Quarter Panel")
        Me.Damage_List.Items.Add("Front O/S Door")
        Me.Damage_List.Items.Add("Front N/S Door")
        Me.Damage_List.Items.Add("Rear O/S Door")
        Me.Damage_List.Items.Add("Rear N/S Door")
        Me.Damage_List.Items.Add("Front O/S Door Sill")
        Me.Damage_List.Items.Add("Front N/S Door Sill")
        Me.Damage_List.Items.Add("Rear O/S Door Sill")
        Me.Damage_List.Items.Add("Rear N/S Door Sill")
        Dim executableItems_Spray As New List(Of ExecutableItem)
        executableItems_Spray.Add(New ExecutableItem With {.Text = "Standard", .Method = AddressOf Spray_Standard})
        executableItems_Spray.Add(New ExecutableItem With {.Text = "Parking Sensors", .Method = AddressOf Spray_Parking_Sensors})
        executableItems_Spray.Add(New ExecutableItem With {.Text = "Wing Mirror", .Method = AddressOf Spray_Wing_Mirror})
        executableItems_Spray.Add(New ExecutableItem With {.Text = "Door Moulding", .Method = AddressOf Spray_Door_Moulding})
        With ComboBox_Spray
            .DisplayMember = "Text"
            .ValueMember = "Method"
            .DataSource = executableItems_Spray
        End With
    End Sub
it populates the combo box and here is the code in the combobox
VB.NET:
Private Sub ComboBox_Spray_SelectedIndexChanged(ByVal sender As  System.Object, ByVal e As System.EventArgs) Handles  ComboBox_Spray.SelectedIndexChanged
        Call clear_Price()'This work's no Error here
        method = DirectCast(ComboBox_Spray.SelectedValue, Action)
        method.Invoke()
    End Sub
the method.invoke is what calls the sub Parking_Sensors
VB.NET:
 Private Sub Spray_Parking_Sensors()
        [COLOR=red]Call Clear_List() ' Here is where the error is at[/COLOR]
        Damage_List.Items.Add("Parking Sensors")
        Damage_List.SetItemCheckState(0, CheckState.Checked)
        Price_Subtotal = 25
        Car_Price_Subtotal.Value = Price_Subtotal
        Call discount()
here is the code for the clear list
VB.NET:
[COLOR=red]Private Sub Clear_List()
        If Damage_List.Items.Count > 0 Then
            [/COLOR][COLOR=red]Damage_List.Items.Clear()' here is where i get the system.stackOverflowException[/COLOR]                                                    
[COLOR=red]         End If[/COLOR]
    End Sub
I Really cant figure this out and im am Totally Baffeled
 
Last edited:
il post this now i have edited it a bit and still getings errors GRR!!!!!!

VB.NET:
Private Sub Damage_List_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles Damage_List.ItemCheck
       [COLOR=red] If Me.Damage_List.Items.Count = 0 Then
            Exit Sub ' this should stop the funtion repeating itself after the list has been cleared, but its not
        End If[/COLOR]
        Dim chkCount As Integer = Damage_List.CheckedItems.Count
        If e.NewValue = CheckState.Checked Then
            chkCount += 1
        Else
            chkCount -= 1
        End If

        Damagecount = chkCount
        If Damagecount <= 0 Then
            Call clear_Price()
        End If
        method.Invoke()
        Call discount()
    End Sub
 
OMFG THIS IS SOO PISSING ME OFF one bit of code is working yet another is not and their are pretty much the same
this code works
VB.NET:
Private Sub Spray_Standard()
        Dim count As Integer = Damage_List.Items.Count
        If count >= 1 Then
            Call Clear_List()
        End If
        Me.Damage_List.Items.Add("Front O/S Bumper Corner")
        Me.Damage_List.Items.Add("Front N/S Bumper Corner")
        Me.Damage_List.Items.Add("Front Bumper Centre")
        Me.Damage_List.Items.Add("Rear O/S Bumper Corner")
        Me.Damage_List.Items.Add("Rear N/S Bumper Corner")
        Me.Damage_List.Items.Add("Rear Bumper Centre")
        Me.Damage_List.Items.Add("Front O/S Wing")
        Me.Damage_List.Items.Add("Front N/S Wing")
        Me.Damage_List.Items.Add("Rear O/S Quarter Panel")
        Me.Damage_List.Items.Add("Rear N/S Quarter Panel")
        Me.Damage_List.Items.Add("Front O/S Door")
        Me.Damage_List.Items.Add("Front N/S Door")
        Me.Damage_List.Items.Add("Rear O/S Door")
        Me.Damage_List.Items.Add("Rear N/S Door")
        Me.Damage_List.Items.Add("Front O/S Door Sill")
        Me.Damage_List.Items.Add("Front N/S Door Sill")
        Me.Damage_List.Items.Add("Rear O/S Door Sill")
        Me.Damage_List.Items.Add("Rear N/S Door Sill")
        Price_Subtotal = (Damagecount * 65)
        Car_Price_Subtotal.Value = Price_Subtotal
    End Sub
this code doesn't
VB.NET:
Private Sub Spray_Parking_Sensors()
        Dim count As Integer = Damage_List.Items.Count
        If count >= 1 Then
            Call Clear_List()
        End If
        Damage_List.Items.Add("Parking Sensors")
        Damage_List.SetItemCheckState(0, CheckState.Checked)
        Price_Subtotal = 25
        Car_Price_Subtotal.Value = Price_Subtotal
    End Sub

why they use the same method for checking if the list has items in it or not, they call the same funtion to clear the list and use the same method for inserting items into the list
 
Not sure where the code actually enters a loop, but if the stock overflow happens in the Clear_List sub, there must be some other code you didn't post because I can't see its called from anywhere...?

My suggestion is to debug. Set a breakpoint where the stack overflow happens and when it gets there (let two-three passes go by to be sure you're in the right spot), skip that line and go line by line until it exists the function so you can see where its called from. When it returns to the last function, there's your problem, probably. Alternatively, try F8 into that line and see where that leads you. Most likely to a event which is triggered everytime the Clear() is given.
 
thanks for the reply irza, it was solved by joshbds assisting with Teamviewer,
the clear list would trigger the damage_list event which would trigger another funtion that triggeres the clear list which triggered the damage_list again.
 
Back
Top