473,396 Members | 1,666 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,396 software developers and data experts.

Passing If Typeof...Is...X as a parameter

I have a sub routine that performs an operation on all of
the controls on an ASP.NET page using the If TypeOf..Is X
statement. I want to pass the class, X, in as a
parameter. Is this possible?

Sub(byval x as ???)
For i = 0 to Controls.count -1
If Typeof controls(i) Is X then
'Do something
End if
Next
End sub
Jul 21 '05 #1
2 1434
Alex,
Use the alternate form:
Sub(byval x as System.Type)
For i = 0 to Controls.count -1
If controls(i).GetType() Is x then
'Do something
End if
Of course then the types need to match exactly, control cannot be a subtype
of x.

If you care about subtypes, then you can try:

If x.IsAssignableFrom(controls(i).GetType()) Then

Double check the IsAssignableFrom, I may have got x & control's type
backwards.

Hope this helps
Jay

"AlexB" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl... I have a sub routine that performs an operation on all of
the controls on an ASP.NET page using the If TypeOf..Is X
statement. I want to pass the class, X, in as a
parameter. Is this possible?

Sub(byval x as ???)
For i = 0 to Controls.count -1
If Typeof controls(i) Is X then
'Do something
End if
Next
End sub

Jul 21 '05 #2
Doh!

I should add when you call your sub you need to use GetType(TextBox) to pass
the type of TextBox, replace TextBox with the name of the actual control you
are interested in.

However I'm not entirely sure what you think this is going to buy you...

Hope this helps
Jay

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:ea****************@tk2msftngp13.phx.gbl...
Alex,
Use the alternate form:
Sub(byval x as System.Type)
For i = 0 to Controls.count -1
If controls(i).GetType() Is x then
'Do something
End if
Of course then the types need to match exactly, control cannot be a

subtype of x.

If you care about subtypes, then you can try:

If x.IsAssignableFrom(controls(i).GetType()) Then

Double check the IsAssignableFrom, I may have got x & control's type
backwards.

Hope this helps
Jay

"AlexB" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
I have a sub routine that performs an operation on all of
the controls on an ASP.NET page using the If TypeOf..Is X
statement. I want to pass the class, X, in as a
parameter. Is this possible?

Sub(byval x as ???)
For i = 0 to Controls.count -1
If Typeof controls(i) Is X then
'Do something
End if
Next
End sub


Jul 21 '05 #3

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

Similar topics

6
by: Catherine Jones | last post by:
Hi all, we need urgent help in a matter. We are trying to pass a COM object from the client to server and are facing some problems in the same. We've our client in C# as well as the Server...
2
by: Helen | last post by:
Hi I want to write a function that searches a control's ancestors until it finds a panel of a particular type. I need to do exactly the same thing for three different types of panels, so I was...
7
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a...
5
by: James Wong | last post by:
Dear all, I've a web service function and it contains a parameter in System.Text.Encoding. I found that the data type of this parameter in caller application becomes MyWebSvcName.Encoding...
2
by: AlexB | last post by:
I have a sub routine that performs an operation on all of the controls on an ASP.NET page using the If TypeOf..Is X statement. I want to pass the class, X, in as a parameter. Is this possible? ...
4
by: Charles Churchill | last post by:
I apologize if this question has been asked before, but after about half an hour of searching I haven't been able to find an answer online. My code is beloiw, with comments pertaining to my...
1
by: Néstor Sánchez A. | last post by:
Hi, is there a way, maybe using reflection, to use a generic class passing the type parameter dynamicly (not kwnowing the exact type at compile time)? I tried the next example, but doesn't work: ...
5
by: Jay | last post by:
I want to be able to pass different enums into a method which makes use of the enum in some way. I've put together a simplified example below. How do I correctly pass an enum (eg Test1 or Test2 as...
2
by: william.w.oneill | last post by:
I have an application that takes a few command line parameters. As recommended by others in this group, I'm using a named mutex to ensure that only one instance of the application is running. My...
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: 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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.