Link to home
Start Free TrialLog in
Avatar of Basicfarmer
BasicfarmerFlag for United States of America

asked on

Select Case statement for selected tab page

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

ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.  =)
Avatar of Basicfarmer

ASKER

Thanks guys, both of your solutions work. I prefer James's solution for the reasons he stated.