Type conversion Object to unknown Objectype

Napivo1972

Well-known member
Joined
Aug 31, 2004
Messages
75
I can hear some of you already laugh for this certainly is a Question in the easy cathegory.

To cast an onbect to a known objecttype I just do:

Dim fntfont as font = Directcast(Myobject,font)

That
 
You could always use the TypeOf operator e.g.
Code:
Dim o As Object

If TypeOf o Is Pen Then
     o is a Pen handle correctly here
End If
however you may be better off handling the whole idea differently - is there a particular reason why a single variable could contain two different classes of objects? Often it would be much better to use a different variable for each object type. This way you can strongly type things and let the compiler identify plenty sources of error.
Any chance you could post more of the code to see if it could be improved somehow?
 
Back
Top