Results 1 to 12 of 12

Thread: SSTab as a Container

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    13

    SSTab as a Container

    I wrote a function that loops through all the controls of a form, so that I could set some of the properties of all those that belong to a certain container.

    This is a small version of that function:

    VB Code:
    1. Public Sub setControls(ByVal formulary As Form, ByVal prefix As String, text As String)
    2.     prefix = UCase(prefix)
    3.     Dim control As control
    4.    
    5.     For Each control In formulary.Controls
    6.         If InStr(1, UCase(control.Container.Name), prefix) > 0 Then
    7.             If TypeName(control) = "TextBox" Then
    8.                 control.text = text
    9.             End If
    10.         End If
    11.     Next
    12. End Sub
    When I call the function
    VB Code:
    1. Call setControls(Me, "Frame", "Hi")
    it sets every textbox text to "Hi" in all containers whose name starts on "Frame". BUT (cause there is a but) in the case of a SSTab control it's different, because I can't change the properties of the members of just ONE specific tab since the container is the SSTab control and not something like SSTab(1).

    The thing is: is there any way to know is a control belongs to a specific tab in a SSTab control?

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: SSTab as a Container

    You can use the Tag property of the textboxes to indicate which tab it will show up in, and then check that when you want to change a property of the textboxes in one tab of the sstab.


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    13

    Re: SSTab as a Container

    Thanks. But I have so many controls in the tabs that going one by one is a little bit boring, besides it makes less automatic, since I have to remember doing it every time I make a SSTab control.

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: SSTab as a Container

    To find out which Tab a control is on you would need to loop through the Tabs, setting each Tab as the current Tab. When a Tab becomes current, the Left property of all controls is adjusted - ie the controls are moved into view.

    You can then check the Left property of the Control. If it is > 0 you can assume it is on that Tab.

    VB Code:
    1. Dim x As Control
    2.     Dim lngTab As Long
    3.    
    4.     For Each x In Controls
    5.         If x.Container.Name = "SSTab1" Then
    6.             For lngTab = 0 To SSTab1.Tabs - 1
    7.  
    8.                 SSTab1.Tab = lngTab ' set current tab
    9.  
    10.                 If x.Left > 0 Then
    11.                     Debug.Print x.Name; " is on tab "; lngTab
    12.                     Exit For
    13.                 End If
    14.  
    15.             Next
    16.         End If
    17.     Next

    Just another reason I always recommend to use a Frame Control on each Tab and place the controls in the Frame.

  5. #5
    Hyperactive Member guyvdn's Avatar
    Join Date
    Oct 2002
    Location
    Belgium
    Posts
    336

    Re: SSTab as a Container

    You can place the controls on each tab in a Frame wih no border
    To deny our own impulses is to deny the very thing that makes us human

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    13

    Re: SSTab as a Container

    There are frames in the tabs with controls inside them and the code above didn't work.

  7. #7
    Hyperactive Member guyvdn's Avatar
    Join Date
    Oct 2002
    Location
    Belgium
    Posts
    336

    Re: SSTab as a Container

    I have a form with a SSTab containing a Frame that has a textbox in it. When I use your function like this
    VB Code:
    1. setControls Me, "Frame1", "Hello"
    It does work
    To deny our own impulses is to deny the very thing that makes us human

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: SSTab as a Container

    the code above didn't work.
    Can you explain what you mean by "didn't work"?

  9. #9

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    13

    Re: SSTab as a Container

    I placed a control in the second tab and it says that is in the 1st one

  10. #10
    Hyperactive Member guyvdn's Avatar
    Join Date
    Oct 2002
    Location
    Belgium
    Posts
    336

    Re: SSTab as a Container

    the tab indexes are 0 based, thus the tab with index 1 is the second tab
    To deny our own impulses is to deny the very thing that makes us human

  11. #11

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    13

    Re: SSTab as a Container

    Of course, maybe I should've said:
    "I placed a control in the 9th tab and it says that is in the 1st one"
    It doesn't matter where you place it. It always says its the 1st one (that is the 0 tab of course )
    VB Code:
    1. setControls Me, "Frame1", "Hello"
    I know the function works, but that isn't the problem. The problem is to know if a control is on a specific tab inside the SSTab control.

    What I was really trying to do I have done in VB .NET and that is to make a function that recursively goes through a container looking for its children and its children's children and so on.

    Lets supose I have a frame with frames inside, and those frames have frames inside, and these have textboxes. How can I change the text in the textboxes in just one call, using the frame name that contains all the frames as an argument?

  12. #12
    Hyperactive Member guyvdn's Avatar
    Join Date
    Oct 2002
    Location
    Belgium
    Posts
    336

    Re: SSTab as a Container

    You can't go recursive through the children, but you can go through the containers of the controls recusive .

    I made a form with a SStab with a frame in tab 1 and textboxes al over the place. It also works for frames within frames.

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.     ChangeText Me.Name, "I am on the form" 'Change the text of all te textboxes
    4.     ChangeText SSTab1.Name, "I am on the Tab control" 'Change the text of the textboxes on the sstab
    5.     ChangeText Frame1.Name, "I am on tab 1" 'change the text of the textboxes inside frame1
    6.  
    7. End Sub
    8.  
    9. Private Sub ChangeText(strContainer As String, text As String)
    10.  
    11.     Dim objControl As control
    12.     Dim objContainer As control
    13.  
    14.     For Each objControl In Me.Controls
    15.         If TypeName(objControl) = "TextBox" Then
    16.             Set objContainer = objControl
    17.             While (objContainer.container.Name <> strContainer) And (objContainer.container.Name <> Me.Name)
    18.                Set objContainer = objContainer.container
    19.             Wend
    20.             If objContainer.container.Name = strContainer Then
    21.                 objControl.text = text
    22.             End If
    23.         End If
    24.     Next objControl
    25.  
    26. End Sub
    To deny our own impulses is to deny the very thing that makes us human

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