Home All Groups Group Topic Archive Search About

Is there an expected return difference between the following two codes

Author
4 Mar 2006 2:12 PM
academic
Is there an expected difference between the following?

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

The second way seems to work OK

Public ReadOnly Property GetContextMenuControlWindowsExplorer() As
ContextMenuStrip

Get

Dim tmp As ContextMenuStrip = New ContextMenuStrip

..snip

GetContextMenuControlWindowsExplorer = tmp THIS

Return tmp
OR THIS

End Get

End Property

Author
4 Mar 2006 3:45 PM
David Anton
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



Show quoteHide quote
"academic" wrote:

> Is there an expected difference between the following?
>
> Stepping seems to show that the first way
> GetContextMenuControlWindowsExplorer
> does exhibit the correct data in this sub
> But not in the calling routine.
>
> The second way seems to work OK
>
> Public ReadOnly Property GetContextMenuControlWindowsExplorer() As
> ContextMenuStrip
>
> Get
>
> Dim tmp As ContextMenuStrip = New ContextMenuStrip
>
> ..snip
>
> GetContextMenuControlWindowsExplorer = tmp THIS
>
> Return tmp
> OR THIS
>
> End Get
>
> End Property
>
>
>
Author
4 Mar 2006 3:57 PM
academic
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


Show quoteHide quote
"David Anton" <DavidAn***@discussions.microsoft.com> wrote in message
news:453AF17B-5FF4-4398-8C9F-C5F9D6998FF0@microsoft.com...
> 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
>> GetContextMenuControlWindowsExplorer
>> does exhibit the correct data in this sub
>> But not in the calling routine.
>>
>> The second way seems to work OK
>>
>> Public ReadOnly Property GetContextMenuControlWindowsExplorer() As
>> ContextMenuStrip
>>
>> Get
>>
>> Dim tmp As ContextMenuStrip = New ContextMenuStrip
>>
>> ..snip
>>
>> GetContextMenuControlWindowsExplorer = tmp THIS
>>
>> Return tmp
>> OR THIS
>>
>> End Get
>>
>> End Property
>>
>>
>>
Author
4 Mar 2006 7:19 PM
David Anton
Are you sure that the "GetContextMenuControlWindowsExplorer = 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



Show quoteHide quote
"academic" wrote:

> 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" <DavidAn***@discussions.microsoft.com> wrote in message
> news:453AF17B-5FF4-4398-8C9F-C5F9D6998FF0@microsoft.com...
> > 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
> >> GetContextMenuControlWindowsExplorer
> >> does exhibit the correct data in this sub
> >> But not in the calling routine.
> >>
> >> The second way seems to work OK
> >>
> >> Public ReadOnly Property GetContextMenuControlWindowsExplorer() As
> >> ContextMenuStrip
> >>
> >> Get
> >>
> >> Dim tmp As ContextMenuStrip = New ContextMenuStrip
> >>
> >> ..snip
> >>
> >> GetContextMenuControlWindowsExplorer = tmp THIS
> >>
> >> Return tmp
> >> OR THIS
> >>
> >> End Get
> >>
> >> End Property
> >>
> >>
> >>
>
>
>
Author
4 Mar 2006 7:53 PM
academic
That's a thought.

Thanks

Show quoteHide quote
"David Anton" <DavidAn***@discussions.microsoft.com> wrote in message
news:70B40D3F-F88B-4394-A45E-C739FA0A9E9D@microsoft.com...
> Are you sure that the "GetContextMenuControlWindowsExplorer = 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:
>
>> 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" <DavidAn***@discussions.microsoft.com> wrote in message
>> news:453AF17B-5FF4-4398-8C9F-C5F9D6998FF0@microsoft.com...
>> > 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
>> >> GetContextMenuControlWindowsExplorer
>> >> does exhibit the correct data in this sub
>> >> But not in the calling routine.
>> >>
>> >> The second way seems to work OK
>> >>
>> >> Public ReadOnly Property GetContextMenuControlWindowsExplorer() As
>> >> ContextMenuStrip
>> >>
>> >> Get
>> >>
>> >> Dim tmp As ContextMenuStrip = New ContextMenuStrip
>> >>
>> >> ..snip
>> >>
>> >> GetContextMenuControlWindowsExplorer = tmp THIS
>> >>
>> >> Return tmp
>> >> OR THIS
>> >>
>> >> End Get
>> >>
>> >> End Property
>> >>
>> >>
>> >>
>>
>>
>>