dcsimg
Results 1 to 3 of 3

Thread: Copy all contents of a Tab in SStab into another

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2016
    Posts
    19

    Copy all contents of a Tab in SStab into another

    In a my project I have an indexed sstab container and I want to dynamically increase or decrease the number of tabs by copying all the content from the first into the new ones so that they all have the same contents (Frame, msflexgrid, etc.) with the same dimensions and locations. How can I do it? Is it possible with a "For ... each" loop?

  2. #2
    New Member
    Join Date
    Jan 2017
    Posts
    6

    Re: Copy all contents of a Tab in SStab into another

    Here is a simply way to copy the contents o a Tab is creating the controls as a control array.
    Now a control, in a SSTab, is in the current tab is if the left property is postive else left is negative.
    It could be used for positioning correctly the loaded control in the correct tab.
    I don't know how automate the Load of the new tab, but it can be done manually.
    You can see how to do it in the atacched file
    Attached Files Attached Files

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,596

    Re: Copy all contents of a Tab in SStab into another

    Here's some code that may help you to understand how the SSTab works. It's just used to dynamically (runtime) change the tab on which a control resides (be sure to read my comments in that code):

    Code:
    
    
    Public Sub ChangeTheSSTab(SSctl As Control, ctl() As Control, OldTab As Long, NewTab As Long, Optional bRestoreTheTab As Boolean)
        ' Hide the form with the SSTab before doing this.
        ' You must get the OldTab correct or everything blows up.
        ' Alternatively, this procedure could have "found" it, but that wastes time.
        ' This procedure does NOT work in form_load, but it DOES work in form_activate.
        ' Also, when using this, don't forget to deal with the TabIndex if you need to !!!!
        Dim OrigTab As Long
        Dim i As Long
        '
        If bRestoreTheTab Then OrigTab = SSctl.Tab
        '
        SSctl.Tab = OldTab
        For i = LBound(ctl) To UBound(ctl)
            If TypeName(ctl(i)) = "Line" Then
                ctl(i).x1 = ctl(i).x1 - 75000
                ctl(i).x2 = ctl(i).x2 - 75000
            Else
                ctl(i).Left = ctl(i).Left - 75000
            End If
        Next i
        SSctl.Tab = NewTab
        For i = LBound(ctl) To UBound(ctl)
            If TypeName(ctl(i)) = "Line" Then
                ctl(i).x1 = ctl(i).x1 + 75000
                ctl(i).x2 = ctl(i).x2 + 75000
            Else
                ctl(i).Left = ctl(i).Left + 75000
            End If
        Next i
        '
        If bRestoreTheTab Then SSctl.Tab = OrigTab
    End Sub
    
    

    Some people are confused about this, but the SSTab control is a single container. Each tab isn't a separate container. That code above sort of illustrates this.

    ---------

    And also, in one spot, I do pretty much exactly what you outlined. However, it's so integrated into my software that it's difficult to cut out. Basically, in design view, I've got an SSTab with one tab, and a zero-indexed invisible control for any/all controls I may want to add as tabs are dynamically added.

    Basically, I increment the SSTab.Tabs property to add tabs. Then, I use SSTab.Tab to set the new tab as current. And then, I just use Load txt(NextIndex) to add controls, using txt(NextIndex).Container = SSTab to set the container (remembering to set the .Tab property before doing this).

    Then, just set your .Left and .Top properties of your controls, and you've got it. Here's a code snippet (not complete) that shows how I do it. The rs is a DAO Recordset that defines how many tabs and controls I want.

    Code:
    
        '
        ' Now we build the SSTab.
        '
        ' Just add all the tabs first.
        iTab = 0
        rs.Index = "PrimaryKey"
        rs.MoveFirst    ' We've already verified that it has records.
        '
        Do While Not rs.EOF
            If iTab <> 0 Then tabKeywords.Tabs = tabKeywords.Tabs + 1
            lInc iTab
            rs.MoveNext
        Loop
        '
        ' Figure out how many tab rows.
        ' iTab will be a true count at this point.
        iTabRows = (iTab + 3) \ 4
        Height = Height + (iTabRows - 1) * tabKeywords.TabHeight
        Top = (ScreenHeight - Height) \ 3
        tabKeywords.Height = tabKeywords.Height + (iTabRows - 1) * tabKeywords.TabHeight
        '
        ' And now add all the comboboxes.
        iTab = 0
        rs.Index = "PrimaryKey"
        rs.MoveFirst    ' We've already verified that it has records.
        '
        Const TopDiff = 420
        Const lblTopFirst = 840
        Const cboTopFirst = 780
        Const cmdTopFirst = 840
        Const lblLeft = 3300
        Const cboLeft = 7380
        Const cmdLeft = 12120
        Do While Not rs.EOF
            tabKeywords.Tab = iTab
            tabKeywords.TabCaption(iTab) = TextVal(rs![category])
            iCnt = LongValNum(rs![MaxKeywords])
            For i = 1 To iCnt
                lInc ctlIdxAdd
                Load cbo(ctlIdxAdd): Set cbo(ctlIdxAdd).Container = tabKeywords
                Load lbl(ctlIdxAdd): Set lbl(ctlIdxAdd).Container = tabKeywords
                Load cmd(ctlIdxAdd): Set cmd(ctlIdxAdd).Container = tabKeywords
                '
                lbl(ctlIdxAdd).Left = lblLeft
                lbl(ctlIdxAdd).Top = lblTopFirst + ((i - 1) * TopDiff) + ((iTabRows - 1) * tabKeywords.TabHeight)
                lbl(ctlIdxAdd).Visible = True
                lbl(ctlIdxAdd).Caption = TextVal(rs![category]) & " #" & Format$(i) & ":"
                lbl(ctlIdxAdd).Tag = TextVal(rs![category]) ' This is the NON-lower-case version.
                '
                cbo(ctlIdxAdd).Left = cboLeft
                cbo(ctlIdxAdd).Top = cboTopFirst + ((i - 1) * TopDiff) + ((iTabRows - 1) * tabKeywords.TabHeight)
                cbo(ctlIdxAdd).Visible = True
                cbo(ctlIdxAdd).Tag = LCase$(TextVal(rs![category]))
                '
                cmd(ctlIdxAdd).Left = cmdLeft
                cmd(ctlIdxAdd).Top = cmdTopFirst + ((i - 1) * TopDiff) + ((iTabRows - 1) * tabKeywords.TabHeight)
                cmd(ctlIdxAdd).Visible = True
            Next i
            lInc iTab
            rs.MoveNext
        Loop
    
    

    Maybe that'll help.

    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width