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

  • Thread starter Thread starter recurr
  • Start date Start date
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'.
 
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
 
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
 
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
 
Back
Top