Creating Tab control at runtime in VB.Net

I have created a tab control at run time like this

Public Class Form1
    Public sTab As TabControl

            sTab = New TabControl
            sTab.Name = "Tab" & ix
            sTab.Left = 500
            sTab.Width = 1000

            sTab.TabPages.Add(New TabPage("Page 1"))
            sTab.TabPages.Add(New TabPage("Page 2"))
            sTab.TabPages.Add(New TabPage("Page 3"))

End Sub

Now I want to select the a tab page not from clicking on it but from another event such as

Sub B1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B1.Click
end sub

End Class

Why is this wrong???
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Works fine for me. Are you receiving an exception?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
the only thing that I can see with your code is:

sTab.Name = "Tab" & ix

the ix will throw a build error. Other than that, it works fine. Could it be that the tab strip is positioned 500 points from the left and that you cannot see the tab strip?

Perhaps you could be more specific about what is not working?
keymacAuthor Commented:
There should be a

For ix = 1 to 4

Loop around the creation of the stab code

If you click the button the selected tab does not change
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

käµfm³d 👽Commented:
If you are using a loop around this code, then you are creating 4 TabControl objects, but placing them all in the same spot--in essence, you only see 1 TabControl. So what you are viewing as "selected tab does not change," might actually be occurring on one of the TabControls you do not see. Try altering the location for each subsequent TabControl added in your loop.
exactly what I was going to say
remove the loop unless you want 4 tab strips.... I can't see why you would?
to prove the point, add the following line after "sTab.Name = "Tab" & ix"

sTab.Top = 10 + (ix * 100)

this will show all 4 tab strips
then you can click your button and see what happens... only one tab strip responds
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.