473,324 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Properties with different scope

Hi all,

In VB6 you could declare a property with different scope
between the set & get.

I have a base class where I want properties with Protected
Set and Public Get (ie the class that inherits the base
class can set properties, but the end user of the class
can only read them).

I've read lots about "you can't do this in VB.Net" but
can't imagine that Microsoft would take such a drastic
backwards step (though the loss of edit-and-continue may
prove they will!)

Lots of people have recommended naming the properties
differently, ie Protected Property SetWhatever and Public
Property GetWhatever. But I have lots of properties and
doing this kind of undoes all the benefits of OOP!!

Any suggestions? Thanks in advance. George
Nov 20 '05 #1
7 1122
George,
I've read lots about "you can't do this in VB.Net" but
can't imagine that Microsoft would take such a drastic
backwards step (though the loss of edit-and-continue may
prove they will!)


It's true. But the feature should be back in the next version of
VB.NET.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #2
"George Boyd Ratcliff" <Ge******@qubetech.co.uk> schrieb
Hi all,

In VB6 you could declare a property with different scope
between the set & get.

I have a base class where I want properties with Protected
Set and Public Get (ie the class that inherits the base
class can set properties, but the end user of the class
can only read them).
Not possible.
I've read lots about "you can't do this in VB.Net" but
can't imagine that Microsoft would take such a drastic
backwards step (though the loss of edit-and-continue may
prove they will!)
But they did.
Lots of people have recommended naming the properties
differently, ie Protected Property SetWhatever and Public
Property GetWhatever. But I have lots of properties and
doing this kind of undoes all the benefits of OOP!!

Any suggestions? Thanks in advance. George


Wait for the next version. AFAIR different scope levels will be
re-introduced.

http://msdn.microsoft.com/vbasic/whidbey

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
>It's true. But the feature should be back in the next
version of VB.NET.

Mattias


Thanks Mattias. I'm amazed that Microsoft have taken two
versions before sorting this. I think I may have found a
workaround at http://addressof.com/blog/posts/177.aspx
Nov 20 '05 #4
I've heard rumours that this may be brought back in. They're just rumours
though and I don't know for sure.

In the meantime, you can use the following (messy in my opinion) way of
accomplishing this:
----------------------------------------
Private mName As String
Public ReadOnly Property Name() As String
Get
Return mName
End Get
End Property
Protected Sub SetName(Name As String)
mName = Name
End Property
---------------------------------------

Hope this helps,

Trev.
"George Boyd Ratcliff" <Ge******@qubetech.co.uk> wrote in message
news:07****************************@phx.gbl...
Hi all,

In VB6 you could declare a property with different scope
between the set & get.

I have a base class where I want properties with Protected
Set and Public Get (ie the class that inherits the base
class can set properties, but the end user of the class
can only read them).

I've read lots about "you can't do this in VB.Net" but
can't imagine that Microsoft would take such a drastic
backwards step (though the loss of edit-and-continue may
prove they will!)

Lots of people have recommended naming the properties
differently, ie Protected Property SetWhatever and Public
Property GetWhatever. But I have lots of properties and
doing this kind of undoes all the benefits of OOP!!

Any suggestions? Thanks in advance. George

Nov 20 '05 #5
On Thu, 11 Dec 2003 01:45:34 -0800, <an*******@discussions.microsoft.com>
wrote:
It's true. But the feature should be back in the next

version of VB.NET.

Mattias


Thanks Mattias. I'm amazed that Microsoft have taken two
versions before sorting this. I think I may have found a
workaround at http://addressof.com/blog/posts/177.aspx


Why not have a Public ReadOnly Property and a Protected sub to set the
property? Why is the interface solution any better? The code below seems
more intuitive to me.

'\\\\\\\\\\\\\\\
Private m_prop As Integer

Public ReadOnly Property SomeProp() As Integer
Get
Return m_prop
End Get
End Property

Protected Sub SetSomeProp(value As Integer)
m_prop = value
End Sub

'//////////////

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #6
On Thu, 11 Dec 2003 09:49:48 -0000, Codemonkey wrote:
I've heard rumours that this may be brought back in. They're just rumours
though and I don't know for sure.


The rumors are true.
--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #7
Cor
Yes

And if this is going on, maybe people are saying in future:

use C++ that has much simpler to understand code than VB

Just a thought,

Cor
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an...
4
by: Joel Gordon | last post by:
Hi, When I try and compile the a class containing the following method : public void doSomething() { for (int i=0; i<5; i++) { IList list = new ArrayList(); Console.WriteLine( i /...
8
by: Roy Chastain | last post by:
I have tried this on a couple of occasions and each time the resulting program goes into a loop and eventually gets a stack overflow. public __gc BaseClass { __property virtual int get_IntValue...
2
by: Don | last post by:
I'm asking this for a friend of mine, so forgive me if I'm getting some of the terminology wrong (I don't have any experience with ASP.NET). I've got an ASP application that has some classes that...
10
by: Smokey Grindle | last post by:
i want to inherit the list view class, but in the inherited class, hide the Header style property and the view property (basically its a detailed list with always clickable headers) how do I keep...
13
by: Dave | last post by:
When using the properties designer to store application wide properties how do you get this to work across a project group containing an EXE and a collection of DLLs. I'm using C#.Net 2005. I...
13
by: Rob | last post by:
Can you store "public" variables that may be accessed from anywhere and still have a Form (not SubMain) as the designated startup object ? For example.... let's say I want all the form's Text...
11
by: Web Search Store | last post by:
Hello, I set up a web page with 2 user controls. In classic asp, the first one did all the declarations, and the second one used the values, and could reset it. In ASP.Net so far I can't...
26
by: optimistx | last post by:
A variable in global scope var a1 = 'contents of global variable a1'; can be references (with some limitations) as window; // or window.a1; // or even window;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.