473,516 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Using readonly properties in a class...

Like this:

Private _FieldValue As <some type>

Public Property Something As <some type>
Get
Return _FieldValue
End Get
Private Set
_FieldValue = value
End Set
End Property

Tom Dacon
Dacon Software Consulting

"Brad Pears" <br***@truenorthloghomes.comwrote in message
news:Oa**************@TK2MSFTNGP03.phx.gbl...
>I have a class that has readonly properties in it. I am fairly new to OO
design and development so please let me know if this doe snot make sense...

The reasopn why I have these read only porperties is becasue these
particular properties are not set programatically - they are as a result
of a calualtion of two other properties as shown below...

public readonly property PSFLiveFactored() as decimal
Get
return PSFLiveFactored = PSFLive * 1.5
end get
end property

I have one readonly property that is derived from an SQL Stored procedure
(called when the object is instantiated) which selects a row from a view.
This particular view includes some calculated rows - one of which I want a
few of my read only properties to contain - as opposed to the way I am
setting them above. Since I cannot (and do not want anyone to) set this
property in code (hence a readonly property), how do I actaully set an
initial value for a read only property?

Would I have to call a private method in the "Get" area that would then
retrieve the data from the DB and use that returned value to set the
property?
Thanks, Brad
Thanks, Brad

Jun 27 '08 #1
0 1284

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

Similar topics

9
3937
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it will not set the value of the control and will leave the checked status of the checkbox to false when a user selects a new date. this works fine...
0
5546
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 is used to view the state of the running jobs and schedule new jobs. The control also runs in the context of Internet Explorer (we do this so the...
5
10284
by: fred | last post by:
With a Class is there any difference between a readonly property and function besides having to use Get/End Get. Are there any performance/resource advantages for either. Thanks Fred
16
1887
by: Dennis | last post by:
I have a class named "myclass" and an arraylist containing elements of type "MyClass". I want to get the value of a property of "MyClass" (a string type) for one of the arraylist elements. I can get this using: dim b as string b = DirectCast(myarraylist(0),myclass).myproperty However, I want to use an object to define the type "MyClass"...
1
1154
by: Jumping Matt Flash | last post by:
I'm trying to achieve a property within a class which returns a conditional result dependent on the class members values. I will explain.. Public Class Address Private addrCountry As String Public Property Country() As Country
5
1096
by: Rob Meade | last post by:
Hi all, Ok - I guess this one will eventually still end up as a "personal choice" kinda answer, but I thought I'd run it passed the wealth of knowledge and experience that's in this group. Typically when I'm writing my classes I'll have a series of properties which I set to be read only, I'll then, if I need to write some methods for...
11
1914
by: dgk | last post by:
If I have a class with a public variable, isn't this the same as a private variable with a property? ie, isn't this: Public Class MyTest Public MyVar as String End Class the same as this: Public Class MyTest
8
4709
by: Scott M. | last post by:
I've tried following the simple instructions to be able to use MyServices within C#...Add a project reference to Microsoft.VisualBasic.dll and add: "using Microsoft.VisualBasic.MyServices;" to the code module. After that, I expected to be able to use MyClock or MyComputerInfo, but none of the "My" stuff appears in the intellisense. I've...
1
132
by: Brad Pears | last post by:
Perfect. That makes more sense then calling a method to run the Stored Proc and return the value in the read only properties "Get" method because then it would be running that everytime someone wants to use that value. Instead, run it once at object instantiation, then set it once to the private variable, then the read only properties get...
0
1142
by: Simon Woods | last post by:
Hi I was struggling to find a suitable place to ask this question, so if it is not appropriate here and someone can suggest somewhere else please do. My question is concerning IOC containers and Dependency Injection. The scenarios I'm struggling to get my head around is with regard to a) ReadOnly properties. b) Inheritence
0
7408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7581
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7142
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7548
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5714
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.