
Originally Posted by
gracehskuo
hi,please help.basically i have 5 textbox, i want to count the total of textbox only contain data.
for example:
text1.text =""
text2.text = 12.2
text3.text = 12.3
text4.text = 12.4
text5.text = 12.4
txtresult = 4 ,it only counting the textbox contain value as a 1.if textbox is empty = 0
please help.thanks.
Iam not sure you are in right direction (or probably I did not get it right)
Code:
'Place the textboxes in control array
'To count the no. of Non Empty textboxes
Private Sub cmdCalculate_Click()
Dim intNonEmptyBoxes As Integer
intNonEmptyBoxes = 0
For i = 0 To Me.Text1.Count - 1
If Trim(Me.Text1(i).Text) <> "" Then
intNonEmptyBoxes = intNonEmptyBoxes + 1
End If
Next
MsgBox "Non Empty Textboxes = " & intNonEmptyBoxes
End Sub
Code:
'Place the textboxes in control array
'To calculate the totals only if the textbox contains data
Private Sub cmdCalculate_Click()
Dim dblTotal As Double
dblTotal = 0
For i = 0 To Me.Text1.Count - 1
If Trim(Me.Text1(i).Text) <> "" Then
dblTotal = dblTotal + CDbl(Me.Text1(i).Text)
End If
Next
MsgBox "Total is " & dblTotal
End Sub