Solved

Select Case statement for selected tab page

Posted on 2014-02-20
5
1,270 Views
Last Modified: 2014-02-20
How can i make a case statement out of this for 4 tab pages?

If TabControl1.SelectedTab Is TabPage1 Then
     ' Do something
End If

Open in new window

0
Comment
Question by:Basicfarmer
  • 2
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
ID: 39875802
Select Case True
  Case TabControl1.SelectedTab Is TabPage1
    'Do something
  Case TabControl1.SelectedTab Is TabPage2
    'Do something else
...

End Select
1
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 250 total points
ID: 39875803
You'd use SelectedIndex instead like this:
        Select Case TabControl1.SelectedIndex
            Case 0 ' TabPage1

            Case 1 ' TabPage2

            Case 2 ' TabPage3

            Case 3 ' TabPage4

        End Select

Open in new window

0
 
LVL 40
ID: 39875823
Mike's solution works, but mine has at least one advantage.

If you ever rename the TabPage, or move it in the TabControl, it will still work without modification.

I think that when you need to identify a Control, it is always better to go for the Control itself instead of using one of its properties. Properties can change value. An object is always itself.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 39875826
True.  I've always hated the "Select Case True" construct, though.  If I was going to use the control names themselves, then I'd go for an "If...Else If...Else If...Then" construct as I think it's more readable.  That's definitely a personal preference type thing though.  =)
0
 

Author Closing Comment

by:Basicfarmer
ID: 39875869
Thanks guys, both of your solutions work. I prefer James's solution for the reasons he stated.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question