Hi all, I'm fairly new to VB. I'm working on a Windows forms app that will average a set of numbers, the only catch is that there are 10 textboxes(4 in the example for times sake), and not all of the textboxes could be filled with a number...
I know that if i had a given set of numbers:
Dim a, b, c, d As Integer
a = t1.Text
b = t2.Text
c = t3.Text
d = t4.Text
avg.Text = (Val(a) + Val(b) + Val(c) + Val(d)) / 4
but what if only 3 of the textboxes have numbers entered, how can I have vb find out how many textboxes have values entered into them, then use that number to divide by?
I've been trying something like this, I think i'm on the right track:
Dim i As Integer
Dim xCount As Integer
For i = 1 To xCount
For Each c As Control In Me.Controls
If TypeOf c Is TextBox Then
If c.Text > "0" Then
xCount = xCount + 1
End If
End If
Next
Next i
label1.text = xCount