|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Is there an expected return difference between the following two codesStepping 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 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. -- Show quoteHide quoteDavid 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 > > > 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 >> >> >> 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. -- Show quoteHide quoteDavid 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 > >> > >> > >> > > > 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 >> >> >> >> >> >> >> >> >>
Is it worth while in developing VB.NET or C#.NET
tranferring data from Access to SQL Server Express USB Pen Drive Detection - Retrieving Baffeled by Treeview Nodes Index!!!!! crazy UserControl Class in a module or class in a class? Problem with Hashtable Multiple references in the same project. WMI Conversion Very Unpredictable ListBox Behaviour |
|||||||||||||||||||||||