Question Add all values found in the groupbox textboxes

gate7cy

Well-known member
Joined
May 11, 2009
Messages
119
Programming Experience
3-5
I have a groupbox with a number of textboxes. I want to loop through all the textboxes, get their value( text) and add them all together and show it in a final totaltextbox outside the groupbox. This is what i have done but it does not work. The totaltextbox values do not change. Here is my code :

VB.NET:
    Private Sub AGroupBox_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles AGroupBox.VisibleChanged
        Dim xxx As Integer
        Dim tota, ax As Integer
        Dim min As Integer = 6
        If Me.AGroupBox.Visible = True Then
            For Each _control As Control In Me.AGroupBox.Controls
                If TypeOf (_control) Is TextBox Then

                    ax = CInt(_control.Text)
                    xxx = CInt(totalTextBox.Text)
                    tota = CInt(ax + xxx)
                End If
                totalTextBox.Text = CStr(tota)
            Next
        End If
    End Sub

any suggestions. Thanks for the help so far.:)
 
thanks for the reply.
I have tried it placing before the first 'end if' and also tried it after it. It does not work. I tried placing the whole code on other events of the the groupbox , for example the 'lost_focus' event. Still no results.
 
I would start by placing a break point in your loop and ensuring you are actually entering your IF statement.
 
thanks for the replies. when I put it on a button click it works. I do not want to use a button click as I cannot use due to the structure of the winform. Any suggestion what kind of event will work?
 
I would make a sub in the public part of the form that goes around and adds all the values together for you. Then on each event you want it to happen on, just call the sub. Unless there is something that I am not getting, but I believe that would work.
 
Back
Top