An error occurs in this line:
Dim ans As Integer
ans = TMTextBox.Text
Please, do not use
Val[
^] to get integer value, because it's vb specific.
Rather than it, use:
Int32.Parse Method (System) | Microsoft Docs[
^] or
Int32.TryParse Method (System) | Microsoft Docs[
^]
[EDIT]
Usage:
Dim tboxes As List(Of TextBox) = New List(Of TextBox) With {KMTextBox, G1MTextBox, G2MTextBox, G3MTextBox, G4MTextBox, G5MTextBox, G6MTextBox}
Dim result As Integer = 0
For Each txt As TextBox In tboxes
Dim tmpVal As Integer = 0
Dim success As Boolean = Int32.TryParse(txt.Text, tmpVal)
If success Then result += tmpVal
Next
TMTextBox.Text = result.ToString()