Solved

Select Case statement for selected tab page

Posted on 2014-02-20
5
1,447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

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 86

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

729 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