Results 1 to 4 of 4

Thread: How to poit to a TextBox&(1...n)

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    4

    How to poit to a TextBox&(1...n)

    Hi,
    I need to fill many Text Boxes as TextBox1, TextBox2 and so on ... using a FOR stattement

    For i= 1 to n
    ("TextBox" & i).Value = "AAAAAAAAAAA"


    Is it possible?
    Any idea?
    Thanks in advance.

    Giovanni

  2. #2
    Addicted Member Psychotic's Avatar
    Join Date
    May 2004
    Posts
    164

    Re: How to poit to a TextBox&(1...n)

    if you use control array for your textboxes then u can do somthing like.....


    For i = 0 to 5
    text1(i).text = "Text"
    next i
    -Psychotic-

  3. #3
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: How to poit to a TextBox&(1...n)

    In case you don't know how to make control arrays:

    -Put one control on the form and give it a name (for example txtField)
    -Put another control (same type as first one) on the same form and give the same name (txtField) to it too. VB will ask you if you want to create a control array. Answer YES.
    -After that all controls you name the same will be added to the array.

    You will also notice that the Index property of those controls is no longer empty, it now holds the index number of a particular control in the array.

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: How to poit to a TextBox&(1...n)

    As Psycho and Baja suggested Control Array is the way to go, however the following method might also work for you: you would have to set Tag property in design for each textbox so it will function like some identifier or you can use control's name instead.
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim txt As Control
    3.  
    4.     For Each txt In Controls
    5.         If TypeOf txt Is TextBox Then
    6.             Select Case UCase(txt.Tag)
    7.                 Case "FIRST NAME"
    8.                     'do something
    9.                 Case "LAST NAME"
    10.                     'do something
    11.             End Select
    12.         End If
    13.     Next txt
    14.  
    15. 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