GetType and ApplicationClass

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Howard Kaikow

    #1

    GetType and ApplicationClass

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

    "Public member 'GetType' on type 'ApplicationCla ss' 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.Applicatio n.
    TypeName returns ApplicationClas s.

    Am I using GetType correctly?

    Private Sub CheckGetType(By Ref appWord As Word.Applicatio n)
    With lstOut
    Try
    Dim strType As String = appWord.GetType .ToString
    .Items.Add("Get Type: Detected " & strType)
    Catch ex As Exception
    .Items.Add("Get Type(1): " & ex.Message)
    End Try
    Try
    Dim strType As String = gappWord.GetTyp e.ToString
    .Items.Add("Get Type: Detected " & strType)
    Catch ex As Exception
    .Items.Add("Get Type(2): " & ex.Message)
    End Try
    End With
    End Sub

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


  • CT

    #2
    Re: GetType and ApplicationClas s

    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


    "Howard Kaikow" <kaikow@standar ds.com> wrote in message
    news:%23oTjADme FHA.3620@TK2MSF TNGP09.phx.gbl. ..[color=blue]
    > For the code below, for both appWord and gappWord, I get the error
    >
    > "Public member 'GetType' on type 'ApplicationCla ss' 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.Applicatio n.
    > TypeName returns ApplicationClas s.
    >
    > Am I using GetType correctly?
    >
    > Private Sub CheckGetType(By Ref appWord As Word.Applicatio n)
    > With lstOut
    > Try
    > Dim strType As String = appWord.GetType .ToString
    > .Items.Add("Get Type: Detected " & strType)
    > Catch ex As Exception
    > .Items.Add("Get Type(1): " & ex.Message)
    > End Try
    > Try
    > Dim strType As String = gappWord.GetTyp e.ToString
    > .Items.Add("Get Type: Detected " & strType)
    > Catch ex As Exception
    > .Items.Add("Get Type(2): " & ex.Message)
    > End Try
    > End With
    > End Sub
    >
    > --
    > http://www.standards.com/; See Howard Kaikow's web site.
    >
    >[/color]


    Comment

    • Howard Kaikow

      #3
      Re: GetType and ApplicationClas s

      "CT" <carstent@spamm ersgoawaydotnet services.biz> wrote in message
      news:eefduEveFH A.2888@TK2MSFTN GP15.phx.gbl...[color=blue]
      > Howard,
      >
      > I'm not sure what it is you're trying to do, but you can type case using[/color]
      the[color=blue]
      > CType function, like this:
      >
      > Dim strType As String = CType(appWord, Object).GetType .ToString[/color]

      Thanx.
      I'll give it a try.

      I had thought about casting, but I'm trying to detect the type, so casting
      seemed inappropriate.


      Comment

      • Phill.  W

        #4
        Re: GetType and ApplicationClas s

        "Howard Kaikow" <kaikow@standar ds.com> wrote in message
        news:%23oTjADme FHA.3620@TK2MSF TNGP09.phx.gbl. ..[color=blue]
        > For the code below, for both appWord and gappWord, I get the error
        >
        > "Public member 'GetType' on type 'ApplicationCla ss' not found"[/color]

        Is Word.Applicatio n 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.
        [color=blue]
        > I had thought about casting, but I'm trying to detect the type, so
        > casting seemed inappropriate.[/color]

        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.


        Comment

        • Howard Kaikow

          #5
          Re: GetType and ApplicationClas s

          "Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
          news:d9r93e$oor $1@yarrow.open. ac.uk...[color=blue]
          > "Howard Kaikow" <kaikow@standar ds.com> wrote in message
          > news:%23oTjADme FHA.3620@TK2MSF TNGP09.phx.gbl. ..[color=green]
          > > For the code below, for both appWord and gappWord, I get the error
          > >
          > > "Public member 'GetType' on type 'ApplicationCla ss' not found"[/color]
          >
          > Is Word.Applicatio n an Interface?[/color]

          Word.Applicatio n in the ProgID for Word.
          [color=blue]
          > If so, it would have to /explicitly/ include a GetType function for you
          > to use it in this way.
          >
          > GetType( appWord )[/color]

          That's what I was using.[color=blue]
          >
          > /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.[/color]

          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.


          Comment

          Working...