473,804 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

instance of?

I got a object of type 'Control' passed as a argument to a subroutine of
mine. The object is either a Combobox or a TextBox.

I thought the .GetType could be used to check what type of object it was,
but i haven't had any luck.

In Java you got the instanceOf() operator to do this. What's the equilant in
VB.net?


Nov 20 '05 #1
5 13312
Jarod,
Use TypeOf Is:

Dim c As control

If TypeOf c Is ComboBox Then
Dim combo As ComboBox = DirectCast(c, ComboBox)

ElseIf TypeOf c Is TextBox Then
Dim combo As TextBox = DirectCast(c, TextBox )
End If

You can use Object.GetType along with the GetType function, if you want to
know specifically if its the type. I prefer the TypeOf operator as it
supports classes derived from the listed class.

If c.GetType() Is GetType(ComboBo x) Then
Dim combo As ComboBox = DirectCast(c, ComboBox)

ElseIf c.GetType() Is GetType(TextBox ) Then
Dim combo As TextBox = DirectCast(c, TextBox )
End If

Hope this helps
Jay

"Jarod_24" <ja******@hotma il.com> wrote in message
news:ef******** *************** *******@news.te ranews.com...
I got a object of type 'Control' passed as a argument to a subroutine of
mine. The object is either a Combobox or a TextBox.

I thought the .GetType could be used to check what type of object it was,
but i haven't had any luck.

In Java you got the instanceOf() operator to do this. What's the equilant in VB.net?

Nov 20 '05 #2
You can use GetType but, as the name implies, this returns the type not the
string name of the type so you could do this:

If obj.GetType.Nam e.toString = "ComboBox" Then

End If
"Jarod_24" <ja******@hotma il.com> wrote in message
news:ef******** *************** *******@news.te ranews.com...
I got a object of type 'Control' passed as a argument to a subroutine of
mine. The object is either a Combobox or a TextBox.

I thought the .GetType could be used to check what type of object it was,
but i haven't had any luck.

In Java you got the instanceOf() operator to do this. What's the equilant in VB.net?

Nov 20 '05 #3
* "Jarod_24" <ja******@hotma il.com> scripsit:
I got a object of type 'Control' passed as a argument to a subroutine of
mine. The object is either a Combobox or a TextBox.

I thought the .GetType could be used to check what type of object it was,
but i haven't had any luck.

In Java you got the instanceOf() operator to do this. What's the equilant in
VB.net?


\\\
If TypeOf ... Is ComboBox Then
...
End If
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
Thank You, Thank You, Thank you.

This NG is great!!

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:uW******** ********@TK2MSF TNGP12.phx.gbl. ..
Jarod,
Use TypeOf Is:

Dim c As control

If TypeOf c Is ComboBox Then
Dim combo As ComboBox = DirectCast(c, ComboBox)

ElseIf TypeOf c Is TextBox Then
Dim combo As TextBox = DirectCast(c, TextBox )
End If

You can use Object.GetType along with the GetType function, if you want to
know specifically if its the type. I prefer the TypeOf operator as it
supports classes derived from the listed class.

If c.GetType() Is GetType(ComboBo x) Then
Dim combo As ComboBox = DirectCast(c, ComboBox)

ElseIf c.GetType() Is GetType(TextBox ) Then
Dim combo As TextBox = DirectCast(c, TextBox )
End If

Hope this helps
Jay

"Jarod_24" <ja******@hotma il.com> wrote in message
news:ef******** *************** *******@news.te ranews.com...
I got a object of type 'Control' passed as a argument to a subroutine of
mine. The object is either a Combobox or a TextBox.

I thought the .GetType could be used to check what type of object it was, but i haven't had any luck.

In Java you got the instanceOf() operator to do this. What's the
equilant in
VB.net?


Nov 20 '05 #5
"Jarod_24" <ja******@hotma il.com> schrieb
Thank You, Thank You, Thank you.

This NG is great!!
<F1> is also great. ;-)

http://msdn.microsoft.com/library/en...tBelongsTo.asp
In Java you got the instanceOf() operator to do this. What's the equilant

in VB.net?

See also:
http://msdn.microsoft.com/library/en...sOperators.asp

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6

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

Similar topics

5
2373
by: Robert Ferrell | last post by:
I have a question about assigning __call__ to an instance to make that instance callable. I know there has been quite a bit of discussion about this, and I've read all I can find, but I'm still confused. I'd like to have a factory class that takes a string argument and returns the appropriate factory method based on that string. I'd like the instances to be callable. Like this: fact = Factory('SomeThing') aSomeThing = fact(some...
4
3918
by: | last post by:
Hi I have a list containing several instance address, for example: I'd like to invoke a method on each of these instance but I don't know : 1. if its possible 2. how to proceed
18
6962
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I guess I'll try to narrow it down to a few specific questions, but any further input offered on the subject is greatly appreciated: 1. Are all of my class's methods supposed to take 'self' as their first arg? 2. Am I then supposed to call...
2
5567
by: Mike | last post by:
Greetings, Having a major problem here. running version 8.2 on win2003 server. The problem I am having is backing up a database seems to get to the last part of the backup and then fails. This brings the whole instance down and it has to be restarted. In addition the job seems to be stuck in the TOOLSDB as if I try to delete the backup job I get "The task is currently running". So I went to the command line and tried "db2 backup database...
6
8930
by: Hemant Shah | last post by:
Folks, I need to move HOME directory of an instance to another directory. What is the best way of doing it? Is changing password file enough? or dies DB2 store this info in it's own config? I am running UDB 8.2 on Linux and AIX. Thanks.
6
4672
by: Dmitry Karneyev | last post by:
Hi! I guess this question have been asked a lot of times, but please be tolerant and if you have any ideas share it. The question is: how to make availibale only one instance of application and if second one is loaded it must be close and give focus to first one. Thanks for any advice! Dmitry
2
5507
by: Mesan | last post by:
Hello everyone, Thanks to many useful posts in this newsgroup and others, I've been able to come very close to something I've been wanting to do for a very long time. I've figured out how to create a new custom protocol handler in Windows to handle locations like "myProtocol:", which lets me have a shortcut pointing to "myProtocol:myPrimaryKey" and have my application automatically open and display the given account. That's great. I
1
6491
by: vijay.db | last post by:
Hi Team, Very serious problem with my DB2 V8.1 Fixpack 6 running in AIX 5.1 machine. Every one hour my DB2 instance processes are killed and it's going down. Several trap files are generated in the db2 diag log directory. Following the detailed entry in the db2diag.log: 2007-02-28-05.00.10.650672 Instance:****** Node:000 PID:2109578(db2agent (dbname) 0) TID:1 Appid:GA6DA619.C438.002D98045717
12
3121
by: titan nyquist | last post by:
I have a class with data and methods that use it. Everything is contained perfectly THE PROBLEM: A separate thread has to call a method in the current instantiation of this class. There is only ever ONE instantiation of this class, and this outside method in a separate thread has to access it. How do i do this?
1
1731
by: gzeng | last post by:
I am creating a singleton class in C++. Everything is fine except with the object pointers. I cannot instaniate a regular object. But I can define many pointers *aaaa, *bbbb, etc. to the class and access the member functions of the class without using the public Instance() method. Does an pointer to a class an instance in a singleton? Can anybody tell me if this is a good example of singleton? Here is my code run successfully: ...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.