[RESOLVED] count textbox only contain data help!
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.
Re: count textbox only contain data help!
would this help you If trim(me.Text1.Text) <> "" then
Re: count textbox only contain data help!
This will give you the required result
txtresult = 0
If trim(Text1.Text) <> "" THEN TXTRESULT=TXTRESULT+1
If trim(Text2.Text) <> "" THEN TXTRESULT=TXTRESULT+1
If trim(Text3.Text) <> "" THEN TXTRESULT=TXTRESULT+1
If trim(Text4.Text) <> "" THEN TXTRESULT=TXTRESULT+1
If trim(Text5.Text) <> "" THEN TXTRESULT=TXTRESULT+1
Re: count textbox only contain data help!
hi,thanks u guys.i solved the problem.
this is my code::blush:
Code:
If t1 <> "" Then
t1 = 1
End If
If t2 <> "" Then
t2 = 1
End If
If t3 <> "" Then
t3 = 1
End If
If t4 <> "" Then
t4 = 1
End If
If t5 <> "" Then
t5 = 1
End If
Re: [RESOLVED] count textbox only contain data help!
Quote:
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