Results 1 to 14 of 14

Thread: Increasing Text Number

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Bombay
    Posts
    35

    Increasing Text Number

    Hi,

    I have 45 text boxes on my form, I want to check each text box for all the alphabets. So I decided to make a loop in this way

    n=1
    do until n=45
    If textn.text = "A" then
    condition
    end if
    n=n+1
    loop
    but the problem is how the n of textn.text should b assigned value of n.

    plz help

    Thanking you,


    arv1980
    arv

  2. #2
    Hyperactive Member
    Join Date
    Nov 2002
    Location
    india
    Posts
    418
    hi,.

    first take array of text boxes and use this loop

    n=1
    do until n=45
    If text(n).text = "A" then
    condition
    end if
    n=n+1
    loop

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    This may help if you want to add more TextBoxes (no need to change the code):
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim n As Integer
    5.  
    6. For n = 1 To Text1.Count
    7.    If Text1(n).Text = "A" Then
    8.       ' Your condition code here
    9.    End If
    10. Next
    11.  
    12. End Sub

    Generaly tho, Control Arrays start at 0(index). If so use:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim n As Integer
    5.  
    6. For n = [b]0 To Text1.Count - 1[/b]
    7.    If Text1(n).Text = "A" Then
    8.       ' Your condition code here
    9.    End If
    10. Next
    11.  
    12. End Sub

    And...... To speed things up slightly, evaluate the TextBox count once, like:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim n As Integer, tcnt As Integer
    5.  
    6. [b]tcnt = Text1.Count - 1[/b]
    7.  
    8. For n = 0 To tcnt
    9.    If Text1(n).Text = "A" Then
    10.       ' Your condition code here
    11.    End If
    12. Next
    13.  
    14. End Sub
    Last edited by Bruce Fox; Dec 3rd, 2002 at 02:58 AM.

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Bombay
    Posts
    35
    hi

    count doesn't works. it just gives error "count" property not defined.

    thanks
    arv

  5. #5
    Addicted Member Vitani's Avatar
    Join Date
    Jul 2001
    Location
    England
    Posts
    134
    Are you using a load of text boxed named (eg) TextBox1, TextBox2, TextBox3, etc... or a Control array where all the textboxes have the same name (eg TextBox) but all have a unique index which diferetiates betwee them all?

    The latter is the better method
    If you can dream it, you can do it - Moo Power!

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by arv1980
    hi

    count doesn't works. it just gives error "count" property not defined.

    thanks
    It works for me..... do all of your text boxes have the same name? (IE, is the control array set up correctly?)
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Bombay
    Posts
    35
    I m using different text boxes. like text1, text2...... But how about if i use one text box & then compare each character of the text.
    arv

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    VB Code:
    1. Dim ctl As Control
    2.    
    3.     For Each ctl In Controls
    4.         If TypeOf ctl Is TextBox Then
    5.             If ctl.Text = "A" Then
    6.                 ' condition
    7.             End If
    8.         End If
    9.     Next

  9. #9

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Bombay
    Posts
    35
    hi,

    Thanks everyone, but Martin even that doesn't works. It shows ctl as "".
    arv

  10. #10
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Yes. If you just look at ctl it will be "", but put a breakpoint on the If ctl.Text = "A" Then line you will see that ctl.Text has a value equal to whatever is in the textbox. You can also go to the Immediate screen and type ?ctl.Name and it will display the name of the textbox.

  11. #11
    Hyperactive Member Tequila_worm's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    344
    Originally posted by MartinLiss
    VB Code:
    1. Dim ctl As Control
    2.    
    3.     For Each ctl In Controls
    4.         If TypeOf ctl Is TextBox Then
    5.             If ctl.Text = "A" Then
    6.                 ' condition
    7.             End If
    8.         End If
    9.     Next

    This should work for you make sure you are using the right way.
    Get some more info about it on Google.com or search the MSDN Website for more info on For Each Control

  12. #12
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    I want to check each text box for all the alphabets.
    It seems as though you're only checking for "A"?

  13. #13

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Bombay
    Posts
    35
    no it doesn't works. any other option.
    arv

  14. #14

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