473,402 Members | 2,053 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,402 software developers and data experts.

Property with Public Get and Friend Set?

Tom
I have written a property, where I want to have the GET be available to
anyone (i.e. Public); however, I want the SET to be available ONLY to the
class or program itself (i.e. Friend).

In VB6 this was easy, since the Gets and Sets were seperate. How can one do
this in VB.NET?

Tom
Nov 20 '05 #1
17 2938
* "Tom" <to*@nospam.com> scripsit:
I have written a property, where I want to have the GET be available to
anyone (i.e. Public); however, I want the SET to be available ONLY to the
class or program itself (i.e. Friend).

In VB6 this was easy, since the Gets and Sets were seperate. How can one do
this in VB.NET?


You will have to write separate _procedures_, for example a 'GetFoo'
function and a 'SetFoo' sub.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
"Tom" <to*@nospam.com> schrieb
I have written a property, where I want to have the GET be available
to anyone (i.e. Public); however, I want the SET to be available ONLY
to the class or program itself (i.e. Friend).

In VB6 this was easy, since the Gets and Sets were seperate. How can
one do this in VB.NET?


Unfortunatelly, this is not possible in VB.NET. You would have to write a
Set procedure and a Get procedure to individually specify the modifier.
--
Armin

Nov 20 '05 #3
Hi Tom,

The only way that I know takes a lot of patience. You submit a wish to the
VB.NET development team and get all your friends, relatives, neighbours, etc
to do the same. Then you wait for it to come out in a future version.

I'd like it too, or rather Private/Protected Set and Public Get.

Regards,
Fergus
Nov 20 '05 #4
Tom,
What I do is create a public readonly property, then a Set Sub similar to
what Herfried & Armin stated.

This allows consumers (other assemblies) of your class to use the property
notation, while still giving you the 'hidden' method of setting the value.

Something like:

Public Class Person

Private m_name As String

Public Readonly Property Name() As String
Get
Return m_name
End Get
End Property

Friend Sub SetName(ByVal value As String)
m_name = value
End Sub

End Class

However a lot of the times I pass the value to the constructor, and it is
never changed:

Public Class Person

Private ReadOnly m_name As String

Public Sub New(ByVal name As String)
m_name = name
End Sub

Public Readonly Property Name() As String
Get
Return m_name
End Get
End Property

End Class

Where I may make the constructor Fried, as only the current assembly can
create instances of the class.

Hope this helps
Jay

"Tom" <to*@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have written a property, where I want to have the GET be available to
anyone (i.e. Public); however, I want the SET to be available ONLY to the
class or program itself (i.e. Friend).

In VB6 this was easy, since the Gets and Sets were seperate. How can one do this in VB.NET?

Tom

Nov 20 '05 #5
Hi Jay,

|| Where I may make the constructor Fried, as only the
|| current assembly can create instances of the class.

I like to expose the fields directly when I use that keyword.

Class YummyBreakfast
Fried Egg As New BreakfastItem
Fried Sausage As New BreakfastItem
: : :
End Class

Now that's a class which I'd have no trouble consuming and anyone in the
Assembly is welcome to join me ;-)).

Regards,
fergus
Nov 20 '05 #6
Fergus,
Actually I prefer scrambled.

Damn spell checker, why can't it find correctly spelled incorrectly used
words.

Jay

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Hi Jay,

|| Where I may make the constructor Fried, as only the
|| current assembly can create instances of the class.

I like to expose the fields directly when I use that keyword.

Class YummyBreakfast
Fried Egg As New BreakfastItem
Fried Sausage As New BreakfastItem
: : :
End Class

Now that's a class which I'd have no trouble consuming and anyone in the Assembly is welcome to join me ;-)).

Regards,
fergus

Nov 20 '05 #7
* "Fergus Cooney" <fi******@tesco.net> scripsit:
|| Where I may make the constructor Fried, as only the
|| current assembly can create instances of the class.
Bad quoting.
I like to expose the fields directly when I use that keyword.

Class YummyBreakfast
Fried Egg As New BreakfastItem
Fried Sausage As New BreakfastItem
: : :
End Class

Now that's a class which I'd have no trouble consuming and anyone in the
Assembly is welcome to join me ;-)).


I don't see any advantages...

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #8
* "Fergus Cooney" <fi******@tesco.net> scripsit:
The only way that I know takes a lot of patience. You submit a wish to the
VB.NET development team and get all your friends, relatives, neighbours, etc
to do the same. Then you wait for it to come out in a future version.


I remember there were thousands of wishes when the first beta of VB.NET
was available, but they didn't hear at these wishes.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
Herfried,
I don't see any advantages... I think Fergus was giving me a hard time for Fried instead of Friend.

This may be the first time I made it Fried, most of the time I catch myself
making it Fiend.

Jay

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OL**************@TK2MSFTNGP09.phx.gbl... * "Fergus Cooney" <fi******@tesco.net> scripsit:
|| Where I may make the constructor Fried, as only the
|| current assembly can create instances of the class.


Bad quoting.
I like to expose the fields directly when I use that keyword.

Class YummyBreakfast
Fried Egg As New BreakfastItem
Fried Sausage As New BreakfastItem
: : :
End Class

Now that's a class which I'd have no trouble consuming and anyone in the Assembly is welcome to join me ;-)).


I don't see any advantages...

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #10

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl...
Fergus,
Actually I prefer scrambled.

Damn spell checker, why can't it find correctly spelled incorrectly used
words.

Jay

:) isnt that a grammar checker?

Nov 20 '05 #11
* "Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> scripsit:
I don't see any advantages...
I think Fergus was giving me a hard time for Fried instead of Friend.


Ooops. I didn't realize that.
This may be the first time I made it Fried, most of the time I catch myself
making it Fiend.


;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #12
Rick,
I was patially thinking grammar checker, yet I was also thinking something
higher than that.

Jay
"Rick Mogstad" <ri**@NOSPAM.computetosuit.com> wrote in message
news:uD****************@TK2MSFTNGP09.phx.gbl...

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:OX**************@TK2MSFTNGP09.phx.gbl...
Fergus,
Actually I prefer scrambled.

Damn spell checker, why can't it find correctly spelled incorrectly used
words.

Jay

:) isnt that a grammar checker?

Nov 20 '05 #13
Hi Herfried,

Maybe they were too busy with such newness. Maybe some of those wishes are
on the later version lists.

Did you submit any juicy ones yourself?

Regards,
Fergus
Nov 20 '05 #14
* "Fergus Cooney" <fi******@tesco.net> scripsit:
Maybe they were too busy with such newness. Maybe some of those wishes are
on the later version lists.

Did you submit any juicy ones yourself?


No. They won't change it.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #15
Hi Jay,

I prefer scrambled eggs too but you didn't oblige with such a mega typo.
Hmm, but not the scrambled sausages, perhaps.

Lol. When you find that spellchecker you'll be an old, old man. :-(

Regards,
fergus
Nov 20 '05 #16
Hi there,
This may be the first time I made it Fried, most of the time I catch myself

making it Fiend.

That's what I use when I write **my** applications.

VirusMan
Nov 20 '05 #17
On Fri, 17 Oct 2003 16:18:18 -0400, "Tom" <to*@nospam.com> wrote:
I have written a property, where I want to have the GET be available to
anyone (i.e. Public); however, I want the SET to be available ONLY to the
class or program itself (i.e. Friend).

In VB6 this was easy, since the Gets and Sets were seperate. How can one do
this in VB.NET?

Tom


If you are determined to use Property as opposed to individual
accessors (which is far easier), you can go along the lines of the
following:

--begin example--

Public MustInherit Class TestBase
Protected mValue As String

Friend Property Value() As String
Get
Return mValue
End Get
Set(ByVal Value As String)
mValue = Value
End Set
End Property

End Class

Public Class Test
Inherits TestBase

Public Shadows ReadOnly Property Value() As String
Get
Return mValue
End Get
End Property

End Class

--end example--

To set the value from within the same project, you can use:

Dim oTest As Test
...
CType(oTest,TestBase).Value = "Testing"

This can be neatened up by using a separated interface pattern. ITest
is implemented (and therefore exposed), and there is no need to expose
"TestBase" at all.

But I do agree with the other chaps: The following is by far the
easiest:

--begin example--
Public Class Test
Private mValue As String

Public ReadOnly Property Value() As String
Get
Return mValue
End Get
End Property

Friend Sub SetValue(Value As String)
mValue = Value
End Sub

End Class
--end example--

Rgds,

Nov 20 '05 #18

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

Similar topics

14
by: Codemonkey | last post by:
Just a silly question, but why can't you overload a writeonly property with a readonly one? Surely the compiler can tell the difference of which one to call at compile time, depending on if it is...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
2
by: Lance | last post by:
I want to be able to reset a complex property in a PropertyGrid. I know that for properties that are ValueTypes you can include System.ComponentModel.DefaultValue in the declaration of the property....
3
by: Marty McFly | last post by:
Hello, I have a control class that inherits from System.Web.UI.WebControls.Button. When I drag this control from the "My User Controls" tab in the toolbox onto the form, I want it to reflect the...
5
by: RSH | last post by:
I havent been able to set a property from another class with out getting some sort of error. Can someone please tell me what I'm doing wrong here? Public Class Form1
2
by: miben | last post by:
I need to set a variable returned by a readonly property in a class by another class. So the only way to set that value is from a specific class and function. Public Sub Main Dim setter As New...
0
by: AndyB | last post by:
I'm using xsd.exe to generate a typed-dataset. Then using typed dataset tables (datatables containing two columns--a name and a value) to bind to ASP.NET dropdown list controls (for the dropdown...
3
by: jbeteta | last post by:
Hello, I have a problem declaring variables. I need to create an object oRpte as ReportClass on WebForm1.aspx and be able to use its value on WebForm2.aspx. For declaring the property oRpte()...
2
by: Lespaul36 | last post by:
I have a control that I have made that uses a custom class for storage of some of the information. I want it to display in the VS.Net 2003 property grid in the IDE like the Font property does, so...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.