i need some help over here, as i`m quite new to this program.

i have some problem over on how to create.

i need 1 tab to be on the screen but inside the tag i got 2 button.
the button is auto add on whenever i do update on database.

now wat i need is.
i wan my 1st tab to contain 2 button only, then when i hav 3 button it will auto create a extra tab and put the 3rd button on the tab and so on.

therefor, when i update the database.
like; in the database have 6 button.
there will be 3 tab, each hav 2 button.

if can send me some of similar/sample coding.
i need it asap
thanks a lot

best regards
bang

Dani AI

Generated

— good news: this is straightforward with SSTab + runtime controls. was pointing you in the right direction (use a runtime strategy instead of trying to hand-place every button). (daniweb.com)

Plan (practical, reliable):

  • Decide capacity per tab (you said 2). Compute pagesNeeded = (totalButtons + 1) \ 2. Set the SSTab tab count to pagesNeeded (SSTab exposes a Tabs/TabCount setting). Tabs are zero-based, so page 0 is the first page. (wnvs.cyc.edu.tw)
  • For each DB row calculate pageIndex = (i-1) \ 2, then make that page active via SSTab.Tab = pageIndex before adding/moving the control — doing that ensures the SSTab becomes the active container. New controls created by Load or Controls.Add are not visible by default, so set position and .Visible = True after you assign the container. Run this after the form is shown (Form_Activate is safer than Form_Load for this). (stackoverflow.com)

Minimal VB6 pattern (Controls.Add approach — avoids pre-made control arrays):

Private Sub Form_Activate()
  Dim total As Integer: total = GetButtonCountFromDB()
  Dim pages As Integer: pages = (total + 1) \ 2
  If Me.SSTab1.Tabs < pages Then Me.SSTab1.Tabs = pages

  Dim i As Integer
  For i = 1 To total
    Dim pageIndex As Integer: pageIndex = (i - 1) \ 2
    Me.SSTab1.Tab = pageIndex

    Dim btn As CommandButton
    Set btn = Me.Controls.Add("VB.CommandButton", "btnDyn" & i)
    Set btn.Container = Me.SSTab1
    With btn
      .Caption = "Item " & i
      .Left = 300 * ((i - 1) Mod 2)
      .Top = 150
      .Visible = True
    End With
  Next i
End Sub

This pattern (Controls.Add + setting Container after making the page active) is commonly used in VB6; Controls.Add is the alternative to using Load on a control array. (codeguru.com)

Notes and troubleshooting:

  • If you need click events for each dynamic button, either use a design-time control with an Index (control array + Load) so VB wires events automatically, or create a small class wrapper that uses WithEvents to handle events for Controls.Add instances. Also remember SSTab is a valid container (use Set object.Container = container). (xxxmen.github.io)

If anything fails at runtime, report the exact VB6 error or behavior (tab index, tabs count, or control not showing) and paste the small failing snippet.

Recommended Answers

All 2 Replies

Hi
To Create TabUse Control Array

Load SSTab1(NextIndexValueofTab)' Used to create tab

load Command1(NextIndexValueOfCommand) ' used to create button

Command1(Index).container = SSTab1(Index) ' used to set button on required sstab

Just Try This.
I Had no VB in this system so iam unable to check the code this is my idea

Hello
Please set the SSTab And Commabnd1 properties like visible,Top,Left after creaton

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.