GetType and ApplicationClass

  • Thread starter Thread starter Howard Kaikow
  • Start date Start date
H

Howard Kaikow

For the code below, for both appWord and gappWord, I get the error

"Public member 'GetType' on type 'ApplicationClass' not found"

I realize the test for appWord is superflous as the parameter is passed in
as a known type, but gappWord is has a scope of the class, so a test of the
type is valid (making believe the sub does not know the pre-ordained type).

TypeOf returns Word.Application.
TypeName returns ApplicationClass.

Am I using GetType correctly?

Private Sub CheckGetType(ByRef appWord As Word.Application)
With lstOut
Try
Dim strType As String = appWord.GetType.ToString
.Items.Add("GetType: Detected " & strType)
Catch ex As Exception
.Items.Add("GetType(1): " & ex.Message)
End Try
Try
Dim strType As String = gappWord.GetType.ToString
.Items.Add("GetType: Detected " & strType)
Catch ex As Exception
.Items.Add("GetType(2): " & ex.Message)
End Try
End With
End Sub
 
Howard,

I'm not sure what it is you're trying to do, but you can type case using the
CType function, like this:

Dim strType As String = CType(appWord, Object).GetType.ToString
 
CT said:
Howard,

I'm not sure what it is you're trying to do, but you can type case using the
CType function, like this:

Dim strType As String = CType(appWord, Object).GetType.ToString

Thanx.
I'll give it a try.

I had thought about casting, but I'm trying to detect the type, so casting
seemed inappropriate.
 
Howard Kaikow said:
For the code below, for both appWord and gappWord, I get the error

"Public member 'GetType' on type 'ApplicationClass' not found"

Is Word.Application an Interface?
If so, it would have to /explicitly/ include a GetType function for you
to use it in this way.

GetType( appWord )

/might/ do what you want (haven't tried it, I'll admit), or you could use

DirectCast( appWord, Object ).GetType

instead. GetType is definitely defined for an Object and /every/
reference Type derives from Object.
I had thought about casting, but I'm trying to detect the type, so
casting seemed inappropriate.

Don't confuse "casting" with "converting". Casting tells the compiler

Take *this* and treat it like one of *those*

as in

DirectCast( appWord, Object )

(I recommend DirectCast over CType, because the latter tries to be
"clever" and do type conversions for you as well).

Converting /would/ lose the original type information, something like

Dim dtThen as Date = CDate( "2001-01-01" )
Dim sThen as String _
= dtThen.ToString()

HTH,
Phill W.
 
Phill. W said:
Is Word.Application an Interface?

Word.Application in the ProgID for Word.
If so, it would have to /explicitly/ include a GetType function for you
to use it in this way.

GetType( appWord )

That's what I was using.
/might/ do what you want (haven't tried it, I'll admit), or you could use

DirectCast( appWord, Object ).GetType

instead. GetType is definitely defined for an Object and /every/
reference Type derives from Object.

I used CType and the problem was resolved.

DirectCast would likely work too.

My concern was hat I had to cast using GetType, but not with TypeOf or
TypeName.
 

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

Back
Top