Home All Groups Group Topic Archive Search About

GetType and ApplicationClass

Author
26 Jun 2005 3:08 PM
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

--
http://www.standards.com/; See Howard Kaikow's web site.

Author
27 Jun 2005 8:21 AM
CT
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

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105

Show quoteHide quote
"Howard Kaikow" <kai***@standards.com> wrote in message
news:%23oTjADmeFHA.3620@TK2MSFTNGP09.phx.gbl...
> 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
>
> --
> http://www.standards.com/; See Howard Kaikow's web site.
>
>
Author
27 Jun 2005 1:02 PM
Howard Kaikow
"CT" <carstent@spammersgoawaydotnetservices.biz> wrote in message
news:eefduEveFHA.2888@TK2MSFTNGP15.phx.gbl...
> 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.
Author
28 Jun 2005 10:41 AM
Phill. W
"Howard Kaikow" <kai***@standards.com> wrote in message
news:%23oTjADmeFHA.3620@TK2MSFTNGP09.phx.gbl...
> 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.
Author
29 Jun 2005 7:07 PM
Howard Kaikow
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:d9r93e$oor$1@yarrow.open.ac.uk...
> "Howard Kaikow" <kai***@standards.com> wrote in message
> news:%23oTjADmeFHA.3620@TK2MSFTNGP09.phx.gbl...
> > 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?

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.