Solved

Select Case statement for selected tab page

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now