Hi
You are finding the intricacies of writing code :) The issue as I understand it is that you are trying to add to a final calculation. This is always something I would avoid. My approach in such a case is to include the two values in the main calculation having initially set them to zeroes first. During other data being calculated, with these being zero, the Net total is the same as though they were not there. Now, when the values are changed in the TextBoxes, do the entire calculation again - this means the Net value will always be correct.
Of course, if you do not already have a Sub of some sort that you use for overall calculation, it would mean alterations.
It would probably be worth the effort, as the only other way I can think of is that you track every TextBox change and 'UNDO' the changes as needed - this is NOT a trivial way to go,
Now, the question is: do you have a common Calculation Sub?
Here is a sample of what I am saying:
Option Strict On
Option Explicit On
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' add a few values - these would be your
' own calculated values or user input.
TextBox1.Text = 0.ToString("c2")
TextBox2.Text = 0.ToString("c2")
TextBox3.Text = (1.45).ToString("c2")
TextBox4.Text = (2.45).ToString("c2")
TextBox5.Text = (3.55).ToString("c2")
TextBox6.Text = (4.55).ToString("c2")
Calc()
End Sub
Sub Calc()
Dim tot As Decimal = 0.0D
For Each gbc As Control In Controls
If gbc.GetType = GetType(GroupBox) Then
For Each c As Control In gbc.Controls
If c.GetType = GetType(TextBox) Then
tot += GetDecimal(c.Text.Replace("£"c, String.Empty))
End If
Next
End If
Next
Label2.Text = tot.ToString("c2")
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged
Calc()
End Sub
Function GetDecimal(s As String) As Decimal
Dim v As Decimal = 0.0D
If Decimal.TryParse(s, v) Then Return v
Return 0.0D
End Function
End Class