473,385 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why Does This Not Work - DirectCast

Dim CurrentTabPage As Control
CurrentTabPage = DirectCast("tcontrol.SelectedTab.Name",
Control)
MessageBox.Show(CurrentTabPage.Name)
I get a SPECIFIED CAT IS NOT VALID
Simply described:

I want to determine the name of the tabpage that I am on
(it is created dynamically) and then be able to reference
the tabpages properties. That is why I am trying to
convert it to a control.

I think I am missing something simple.

TIA

Paul A. Timmerman
Nov 21 '05 #1
5 1591
> Dim CurrentTabPage As Control
CurrentTabPage = DirectCast("tcontrol.SelectedTab.Name",
Control)


Firstly, Name is a string; 'SelectedTab' is the tabpage you are looking for.
Secondly, you don't need the surrounding double quotes. Thirdly, you can
simply define CurrentTabPage of type 'TabPage' which means you wouldn't need
to cast in the first place since SelectedTab returns an object of type
'TabPage' itself. This is how you can get the reference you the current tab:

dim CurrentTabPage As TabPage = tcontrol.SelectedTab

and then MessageBox.Show(CurrentTabPage.Name)

hope that helps..
Imran.
Nov 21 '05 #2
Try:

CurrentTabPage = DirectCast (tcontrol.SelectedTab, Control)
OR
Dim tabName As String = DirectCast (tcontrol.SelectedTab.Name, String)

Hope this helps.

"Paul Timmerman" <pa************@ticasino.com> wrote in message
news:0a****************************@phx.gbl...
Dim CurrentTabPage As Control
CurrentTabPage = DirectCast("tcontrol.SelectedTab.Name",
Control)
MessageBox.Show(CurrentTabPage.Name)
I get a SPECIFIED CAT IS NOT VALID
Simply described:

I want to determine the name of the tabpage that I am on
(it is created dynamically) and then be able to reference
the tabpages properties. That is why I am trying to
convert it to a control.

I think I am missing something simple.

TIA

Paul A. Timmerman
Nov 21 '05 #3
Paul,

Now you try to use a String as a Control, that does not work.

However when you want to do that in a click event of that tabpage than you
can use by instance this
\\\
Dim tbp As TabControl = DirectCast(sender, TabControl)
Select Case tbp.SelectedTab.Name

etc
///
Cor
Dim CurrentTabPage As Control
CurrentTabPage = DirectCast("tcontrol.SelectedTab.Name",
Control)
MessageBox.Show(CurrentTabPage.Name)
I get a SPECIFIED CAT IS NOT VALID
Simply described:

I want to determine the name of the tabpage that I am on
(it is created dynamically) and then be able to reference
the tabpages properties. That is why I am trying to
convert it to a control.

I think I am missing something simple.

TIA

Paul A. Timmerman

Nov 21 '05 #4
* "Paul Timmerman" <pa************@ticasino.com> scripsit:
Dim CurrentTabPage As Control
CurrentTabPage = DirectCast("tcontrol.SelectedTab.Name",
Control)
MessageBox.Show(CurrentTabPage.Name)
You cannot cast a string to a type. The string is not a subtype of
'Control'.
I want to determine the name of the tabpage that I am on
(it is created dynamically) and then be able to reference
the tabpages properties. That is why I am trying to
convert it to a control.


Why don't you simply use 'Me.TabControl1.SelectedTab.Name'?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
VJ
When you need to cast a String to type you will need to use Reflections.. I
don't have the syntax with me sorry

VJ

"Paul Timmerman" <pa************@ticasino.com> wrote in message
news:0a****************************@phx.gbl...
Dim CurrentTabPage As Control
CurrentTabPage = DirectCast("tcontrol.SelectedTab.Name",
Control)
MessageBox.Show(CurrentTabPage.Name)
I get a SPECIFIED CAT IS NOT VALID
Simply described:

I want to determine the name of the tabpage that I am on
(it is created dynamically) and then be able to reference
the tabpages properties. That is why I am trying to
convert it to a control.

I think I am missing something simple.

TIA

Paul A. Timmerman

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andreas Klemt | last post by:
Hello, what has the better performance and what are you using? Dim myObj As Object = 70 a) Dim myInt As Integer = DirectCast(myObj, Integer) b) Dim myInt As Integer = Convert.ToInt32(myObj) ...
2
by: Andrea Williams | last post by:
I have this line in VB and I need to convert it to C#: Return DirectCast(HttpContext.Current.Session("LastException"), Exception) I've been unable to find an equivelent to DirectCast and I...
6
by: Ot | last post by:
I apparently have a bit to learn about Casting and Conversion. I have been thinking of them as the same but a discussion in another thread leads me to believe that this is wrong thinking. I...
18
by: Martin Williams | last post by:
I have a working version of my survey program, but i'm trying to optimize now. On the last page, i have a sub that examines all of the answers and assigns them to variables for uploading to the...
5
by: Matt | last post by:
Does anyone know or care to find out the speed difference between a directcast call and a direct call? for instance, i might have these lines of code: dim j as collections.arraylist ...
7
by: JohnR | last post by:
I am using dragdrop to drag and drop a custom class instance. When I drag/drop from one window to another window in the same application everything works fine. But when trying to move between the...
36
by: Cap'n Ahab | last post by:
I have used VB3 - VB6, so learning all this OO stuff is reasonably new to me (although I looked at Java a few years ago). Anyway, I thought I would write a small class to begin with, with a...
5
by: sonia.sardana | last post by:
Dim i As String = "10.56" Dim j As String j = DirectCast(i, String) Console.WriteLine(j) OUTPUT- 10.56 I want to ask that i have used directcast in Right way. This ques tion is asked to me...
0
by: Vincent | last post by:
I answered my own question. Here's what I did to solve this: 1. Deleted the "selected value="<%# bind("driver") %>" from the dropdownlist. (i did not have this code in my above posting) 2....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.