Solved

Select Case statement for selected tab page

Posted on 2014-02-20
5
1,373 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

730 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