Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Reference a Custom Form Property Within the Form

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
0
36
US
This may be s stupid question, but I can't seem to find an answer or at least an accepted methodology. When I have a custom property on a form such as:
Code:
Private _LocationRow As DataRow.

Public Property LocationRow() as DataRow
   Get
      Return _LocationRow
   End Get
   Set(ByVal Value as DataRow)
      _LocationRow = Value
   End Set
End Property
How should I use the property value in the rest of the form's code, by using the LocationRow or _LocationRow? Is there an accepted way of naming and using these properties to keep them visually separate from other variables? Open to suggestions.

Auguy
Sylvania/Toledo Ohio
 
I don't think that there is a hard and fast rule.

With your example property it makes no difference, however what happens if you process the values retrieved from or stored in the Private variables using code in the Get and Set methods? ... this is really what you need to consider.

Normally inside the Class I refer directly to the Private variables. In circumstances where I would need to do additional processing in a Get or Set, I tend to have a separate Private Function which is called by the Get or Set methods. Maybe not the most efficient method, but it makes the Properties much easier to read and obviously these Private Functions can be called by any Method in the Class that need access to them. The downside of this method is that you need to know when you have make these additional calls. But this is just the way I prefer to do things.

As far as naming conventions go, I don't like the _ prefix, instead I tend to use F (for Field) as the prefix - however that probably comes from my Pascal / Delphi background.

As far as the names you choose for your Properties is concerned, there shouldn't be any conflict with external Variables because you would refer to the property as InstanceName.PropertyName. For example in your program you could have a variable LocationRow As DataRow, an instance of your class MyDataClass and therefore use something like LocationRow = MyDataClass.LocationRow and there should not be any confusion.

I must stress, though, that everything above is just personal preference.
 

I always use the property, to be consistent throughout the application.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks to both of you for your input.

Auguy
Sylvania/Toledo Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top