How to get what a variable is dimmed as? How to get what an object isdeclared as? If variable or obj

R

recurr

How to get what a variable is dimmed as? How to get what an object is
declared as? If variable or object is Nothing?

I want to do something like the following, but TypeOf and GetType
doesn't seem to work when a variable is Nothing. The watch window is
able to find the type, so why can't I with TypeOf or GetType()?

Public something as SomeClass

Public Sub SomeSub() as Boolean

If TypeOf something Is SomeOtherClass Then

' Do something here

End If

End Sub

? something.GetType() ' prints Referenced object has a value of
'Nothing'.
 
R

recurr

I was trying to do this with Interfaces and not a class. How do I do
this?



Public something as SomeInterface


Public Sub SomeSub() as Boolean


If TypeOf something Is SomeOtherInterface Then


' Do something here


End If


End Sub
 
M

Mattias Sjögren

How to get what a variable is dimmed as? How to get what an object is
declared as? If variable or object is Nothing?

I want to do something like the following, but TypeOf and GetType
doesn't seem to work when a variable is Nothing. The watch window is
able to find the type, so why can't I with TypeOf or GetType()?

Simply because TypeOf and GetType both require an object instance, and
you don't have one.

I don't see why you need to do this. You can see the declared tpye of
a variable just by looking at its declaration and it can't change at
runtime, so
If TypeOf something Is SomeOtherClass Then

(if it was possible) would always evaluate to false.


Mattias
 
R

recurr

Then I could select an Interface by just uncommenting the Interface I
want to work with so I could have Intellisense.

Public theInterface as SomeInterface
'Public theInterace as SomeInterface2



...

If TypeOf theInterface is SomeInterface Then
theInterface = someInterfaceThatWasLoaded
Else
theInterface = someInterface2ThatWasLoaded
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top