CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Symbolic naming

  1. #1
    Join Date
    Apr 2003
    Location
    DFW
    Posts
    2

    Symbolic naming

    does anyone know how to do this in a for loop in VB6

    'txtHI6_Ln5(TabStrip1.SelectedItem.Index - 1).Visible = True
    'txtHI6_Ln6(TabStrip1.SelectedItem.Index - 1).Visible = True
    'txtHI6_Ln7(TabStrip1.SelectedItem.Index - 1).Visible = True
    'txtHI6_Ln8(TabStrip1.SelectedItem.Index - 1).Visible = True
    'txtHI6_Ln9(TabStrip1.SelectedItem.Index - 1).Visible = True
    'txtHI6_Ln10(TabStrip1.SelectedItem.Index - 1).Visible = True
    'txtHI6_Ln11(TabStrip1.SelectedItem.Index - 1).Visible = True

    For i = 5 to 11
    txtHI6_Ln"i"(TabStrip1.SelectedItem.Index - 1).Visible = True

    ...
    next i?

    Thanks , Marc
    Last edited by aa173130; July 16th, 2008 at 03:56 PM.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Symbolic naming

    You could try something like :
    Code:
    Dim I As Integer, Ctl As Control
    For i = 5 to 11
      Set Ctl = Me.Controls("txtHI6_Ln" & Format(i)) ' The Trick Is here :)
      Ctl(TabStrip1.SelectedItem.Index - 1).Visible = True
    Next i
    Give that a shot, it should work. here, I loop from 5 to 11, then, I set the current found control, equal to a variable named Ctl - lastly, I set the Visible property

    I hope it helps!

  3. #3
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Symbolic naming

    Another approach might be to put the textboxes in a frame. Then setting the frame's Visible property can show or hide all the boxes at once.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  4. #4
    Join Date
    Jul 2008
    Location
    Appleton, WI
    Posts
    23

    Re: Symbolic naming

    I like the frame idea...very clever...will add that to my tools.

    I usually use an array/collection for looping though objects and performing the same method.

    You could code the array as

    dim txtArray(11) as TextBox

    then assign each text box to an index in the array.

    use a stepping for loop or a do while loop with a counter to loop through the indexes of the array and perform the method or change the property you want.

    The collection could be used if all the textboxes need it done.

    Dim colTextBoxes as Collection

    Use the collections add method to add the textboxes to the collection.

    You then can use a for each next loop to call the method or set the property for the contents of the whole collection.

    Hope this helps.

    Btw HanneStheGreat, your code looks like .Net Code...however the concept would work by accessing the forms control collection.
    Last edited by VehementSoftware; July 23rd, 2008 at 12:15 AM.

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Symbolic naming

    Quote Originally Posted by VehementSoftware
    Btw HanneStheGreat, your code looks like .Net Code...however the concept would work by accessing the forms control collection.
    Hi.

    Nope, that is pure VB 6 code.

  6. #6
    Join Date
    Jul 2008
    Location
    Appleton, WI
    Posts
    23

    Re: Symbolic naming

    Sorry Hannes, I thought Me was used in .Net, I have never used in 6.0. Just remembered it's My in .Net. Forgive me, still kind of a noob.

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

Featured