Is there an expected return difference between the following two codes

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

    #1

    Is there an expected return difference between the following two codes

    Is there an expected difference between the following?

    Stepping seems to show that the first way
    GetContextMenuC ontrolWindowsEx plorer
    does exhibit the correct data in this sub
    But not in the calling routine.

    The second way seems to work OK

    Public ReadOnly Property GetContextMenuC ontrolWindowsEx plorer() As
    ContextMenuStri p

    Get

    Dim tmp As ContextMenuStri p = New ContextMenuStri p

    ..snip

    GetContextMenuC ontrolWindowsEx plorer = tmp THIS

    Return tmp
    OR THIS

    End Get

    End Property


  • David Anton

    #2
    RE: Is there an expected return difference between the following two c

    When "Return..." is used, the property is immediately exited.
    When you use method name assignment (unique to VB I think), the property
    logic continues with code beyond the method name assignment - if another
    method name assignment is made then the newer value is returned when the
    property exits.
    --
    David Anton
    Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

    Instant C#: VB to C# converter
    Instant VB: C# to VB converter
    Instant C++: C# to C++ converter & VB to C++ converter
    Instant J#: VB to J# converter



    "academic" wrote:
    [color=blue]
    > Is there an expected difference between the following?
    >
    > Stepping seems to show that the first way
    > GetContextMenuC ontrolWindowsEx plorer
    > does exhibit the correct data in this sub
    > But not in the calling routine.
    >
    > The second way seems to work OK
    >
    > Public ReadOnly Property GetContextMenuC ontrolWindowsEx plorer() As
    > ContextMenuStri p
    >
    > Get
    >
    > Dim tmp As ContextMenuStri p = New ContextMenuStri p
    >
    > ..snip
    >
    > GetContextMenuC ontrolWindowsEx plorer = tmp THIS
    >
    > Return tmp
    > OR THIS
    >
    > End Get
    >
    > End Property
    >
    >
    >[/color]

    Comment

    • academic

      #3
      Re: Is there an expected return difference between the following two c

      But it would be surprising if different values are return from the two
      methods, right?

      I'm probably doing something dumb but it seems to me the Return returns what
      I'd expect and the End Get seems to return an object that was just created.

      Thanks


      "David Anton" <DavidAnton@dis cussions.micros oft.com> wrote in message
      news:453AF17B-5FF4-4398-8C9F-C5F9D6998FF0@mi crosoft.com...[color=blue]
      > When "Return..." is used, the property is immediately exited.
      > When you use method name assignment (unique to VB I think), the property
      > logic continues with code beyond the method name assignment - if another
      > method name assignment is made then the newer value is returned when the
      > property exits.
      > --
      > David Anton
      > www.tangiblesoftwaresolutions.com
      > Instant C#: VB to C# converter
      > Instant VB: C# to VB converter
      > Instant C++: C# to C++ converter & VB to C++ converter
      > Instant J#: VB to J# converter
      >
      >
      >
      > "academic" wrote:
      >[color=green]
      >> Is there an expected difference between the following?
      >>
      >> Stepping seems to show that the first way
      >> GetContextMenuC ontrolWindowsEx plorer
      >> does exhibit the correct data in this sub
      >> But not in the calling routine.
      >>
      >> The second way seems to work OK
      >>
      >> Public ReadOnly Property GetContextMenuC ontrolWindowsEx plorer() As
      >> ContextMenuStri p
      >>
      >> Get
      >>
      >> Dim tmp As ContextMenuStri p = New ContextMenuStri p
      >>
      >> ..snip
      >>
      >> GetContextMenuC ontrolWindowsEx plorer = tmp THIS
      >>
      >> Return tmp
      >> OR THIS
      >>
      >> End Get
      >>
      >> End Property
      >>
      >>
      >>[/color][/color]


      Comment

      • David Anton

        #4
        Re: Is there an expected return difference between the following t

        Are you sure that the "GetContextMenu ControlWindowsE xplorer = tmp" line is
        being executed? The only way I can see the scenario you describe is if that
        line doesn't execute.
        I think it's better to use Return statements since they are less ambiguous.
        --
        David Anton
        Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

        Instant C#: VB to C# converter
        Instant VB: C# to VB converter
        Instant C++: C# to C++ converter & VB to C++ converter
        Instant J#: VB to J# converter



        "academic" wrote:
        [color=blue]
        > But it would be surprising if different values are return from the two
        > methods, right?
        >
        > I'm probably doing something dumb but it seems to me the Return returns what
        > I'd expect and the End Get seems to return an object that was just created.
        >
        > Thanks
        >
        >
        > "David Anton" <DavidAnton@dis cussions.micros oft.com> wrote in message
        > news:453AF17B-5FF4-4398-8C9F-C5F9D6998FF0@mi crosoft.com...[color=green]
        > > When "Return..." is used, the property is immediately exited.
        > > When you use method name assignment (unique to VB I think), the property
        > > logic continues with code beyond the method name assignment - if another
        > > method name assignment is made then the newer value is returned when the
        > > property exits.
        > > --
        > > David Anton
        > > www.tangiblesoftwaresolutions.com
        > > Instant C#: VB to C# converter
        > > Instant VB: C# to VB converter
        > > Instant C++: C# to C++ converter & VB to C++ converter
        > > Instant J#: VB to J# converter
        > >
        > >
        > >
        > > "academic" wrote:
        > >[color=darkred]
        > >> Is there an expected difference between the following?
        > >>
        > >> Stepping seems to show that the first way
        > >> GetContextMenuC ontrolWindowsEx plorer
        > >> does exhibit the correct data in this sub
        > >> But not in the calling routine.
        > >>
        > >> The second way seems to work OK
        > >>
        > >> Public ReadOnly Property GetContextMenuC ontrolWindowsEx plorer() As
        > >> ContextMenuStri p
        > >>
        > >> Get
        > >>
        > >> Dim tmp As ContextMenuStri p = New ContextMenuStri p
        > >>
        > >> ..snip
        > >>
        > >> GetContextMenuC ontrolWindowsEx plorer = tmp THIS
        > >>
        > >> Return tmp
        > >> OR THIS
        > >>
        > >> End Get
        > >>
        > >> End Property
        > >>
        > >>
        > >>[/color][/color]
        >
        >
        >[/color]

        Comment

        • academic

          #5
          Re: Is there an expected return difference between the following t

          That's a thought.

          Thanks

          "David Anton" <DavidAnton@dis cussions.micros oft.com> wrote in message
          news:70B40D3F-F88B-4394-A45E-C739FA0A9E9D@mi crosoft.com...[color=blue]
          > Are you sure that the "GetContextMenu ControlWindowsE xplorer = tmp" line is
          > being executed? The only way I can see the scenario you describe is if
          > that
          > line doesn't execute.
          > I think it's better to use Return statements since they are less
          > ambiguous.
          > --
          > David Anton
          > www.tangiblesoftwaresolutions.com
          > Instant C#: VB to C# converter
          > Instant VB: C# to VB converter
          > Instant C++: C# to C++ converter & VB to C++ converter
          > Instant J#: VB to J# converter
          >
          >
          >
          > "academic" wrote:
          >[color=green]
          >> But it would be surprising if different values are return from the two
          >> methods, right?
          >>
          >> I'm probably doing something dumb but it seems to me the Return returns
          >> what
          >> I'd expect and the End Get seems to return an object that was just
          >> created.
          >>
          >> Thanks
          >>
          >>
          >> "David Anton" <DavidAnton@dis cussions.micros oft.com> wrote in message
          >> news:453AF17B-5FF4-4398-8C9F-C5F9D6998FF0@mi crosoft.com...[color=darkred]
          >> > When "Return..." is used, the property is immediately exited.
          >> > When you use method name assignment (unique to VB I think), the
          >> > property
          >> > logic continues with code beyond the method name assignment - if
          >> > another
          >> > method name assignment is made then the newer value is returned when
          >> > the
          >> > property exits.
          >> > --
          >> > David Anton
          >> > www.tangiblesoftwaresolutions.com
          >> > Instant C#: VB to C# converter
          >> > Instant VB: C# to VB converter
          >> > Instant C++: C# to C++ converter & VB to C++ converter
          >> > Instant J#: VB to J# converter
          >> >
          >> >
          >> >
          >> > "academic" wrote:
          >> >
          >> >> Is there an expected difference between the following?
          >> >>
          >> >> Stepping seems to show that the first way
          >> >> GetContextMenuC ontrolWindowsEx plorer
          >> >> does exhibit the correct data in this sub
          >> >> But not in the calling routine.
          >> >>
          >> >> The second way seems to work OK
          >> >>
          >> >> Public ReadOnly Property GetContextMenuC ontrolWindowsEx plorer() As
          >> >> ContextMenuStri p
          >> >>
          >> >> Get
          >> >>
          >> >> Dim tmp As ContextMenuStri p = New ContextMenuStri p
          >> >>
          >> >> ..snip
          >> >>
          >> >> GetContextMenuC ontrolWindowsEx plorer = tmp THIS
          >> >>
          >> >> Return tmp
          >> >> OR THIS
          >> >>
          >> >> End Get
          >> >>
          >> >> End Property
          >> >>
          >> >>
          >> >>[/color]
          >>
          >>
          >>[/color][/color]


          Comment

          Working...