Results 1 to 5 of 5

Thread: [RESOLVED] count textbox only contain data help!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Resolved [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.

  2. #2
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: count textbox only contain data help!

    would this help you If trim(me.Text1.Text) <> "" then

  3. #3
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    275

    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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: count textbox only contain data help!

    hi,thanks u guys.i solved the problem.

    this is my code:
    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

  5. #5
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Wink 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width