Results 1 to 7 of 7

Thread: Control Names

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    42

    Question

    I have ten textboxes on my form which are hidden until being populated. My question is: How do I refer to these textboxes when I'm in a loop? For example - I've tried "Text" & z - when z is set to 2 to no avail.

    Old Man

    [Edited by Old Man on 10-11-2000 at 05:21 PM]
    Using VB6 Professional Ediion

  2. #2
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Change the textboxes into a Control array (set the index property to something other than 0 and their names to the same thing: IE Text1 ...) After you do this, you'd refer to each one by it's name and index like an array: Text1(X) ...
    -Excalibur

  3. #3
    Lively Member
    Join Date
    Aug 2000
    Posts
    125
    make a control array by naming them all them same and setting the index property starting at zero

    you can then refer to them as Text1(x).Visible = True

  4. #4
    Guest
    Or you can do it like this:

    Code:
       For Each MyControl In Me.Controls
          If TypeOf MyControl Is TextBox Then MyControl.Visible = True
       Next

  5. #5
    Guest
    You could also...

    Code:
    Dim Controlx as Control
    For Each Controlx In Me.Controls
      If TypeOf Controlx Is "TextBox" And Left$(Controlx.Name, 4) = "Text" Then Controlx.Visible = True
    Next
    WITHOUT setting a control array.

  6. #6
    Guest
    that might cause conflicts if there are more TextBoxes on the form with other uses. If you perfer to use Matthew Gate's solution, I suggest you consider "tagging" the objects you want to work with.

    Code:
    Dim ctl as Control
    
    For Each ctl In Controls
        If TypeOf ctl Is TextBox Then
            If ctl.Tag = "TAGGED" Then
                'Do your code here
            End if
        End if
    Next ctl

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    42

    Talking

    Thanks very much for your help! I got it.

    Let's do lunch!!


    Old Man
    Using VB6 Professional Ediion

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