?
Solved

More Property help

Posted on 2006-07-13
12
Medium Priority
?
245 Views
Last Modified: 2010-04-23
Maybe a dumb question, but I am still trying to grasp properties...

If I'm declaring:

Private a as string
Private b as string
Private c as string

Can I use only 1 property, passing the 'name'?

Public Property MyProperty(myString as String) as String
??
0
Comment
Question by:sirbounty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
12 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17099508
You mean use one property to set the values for a, b and c ? And pass the name of the one to set ?
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17099528
yes ( I think )
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17099634
Then the answer is no.

You can set multiple values from within a single property, but you can't tell it which to set, unless you did it based on the value passed. But if you did that then you would confuse the usage of the property.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:manch
ID: 17099645

   U mean a property like this :

   Public Property MyProp(ByVal str As String) As String
        Get
            Return str
        End Get
        Set(ByVal Value As String)
            If str = "a" Then
                a = value
            ElseIf str = "b" Then
                b = value
            ElseIf str = "c" Then
                c = value
            End If
        End Set
    End Property
0
 
LVL 6

Expert Comment

by:manch
ID: 17099669
one more thing if u want the same values as parameters passed then u have to use the if statements for Get also

i.e.

Get
           If str = "a" Then
                return a
            ElseIf str = "b" Then
                return b
            ElseIf str = "c" Then
                return c
            End If
End Set
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17100636
Great manch - I'll try this out.

What do I reference in my "get"?

If I'm using Int, for example:

Private mintBoard1 as Integer
[...]
Private mintBoard10 as Integer

Public Property BoardLength(byVal myBoard as Integer) As Integer
  Get
    Select Case myBoard
      Case ???  ' Would this be "mintBoard1" or something else?
        Return mintBoard1
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17100644
>> But if you did that then you would confuse the usage of the property.<<

How so?  Remember - I'm still new to Properties...the last thing I need is more confusion! :^)
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17100728
Odd - I haven't got notifications on these last two comments... :(
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 400 total points
ID: 17101251
>> How so?

A property describes something (i.e. Color, Name, Age). If you start making the inner workings overly complicated then you make it more difficult to understand what the property does.

Take an example, which of these makes more sense from a user perspective:

    MyObj.Color("a") = "Blue"
    MyObj.Color("b") = "Red"
    MyObj.Color("c") = "Green"

Or simply:

    MyObj.Color = "Blue"


The first is more confusing for anybody using your class because they would need to understand the inner workings of the object to know what "a", "b" and "c" mean. Whereas the second is a simple property name and it is clear from the syntax what it is doing.

If you need to do different things based on a parameter then you should use a method instead with a name that gives some indication to the user as to what to expect it to do.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17101796
Oh well - it just looked sloppy to me to have

private mVar1
private mVar2
[...]
private mVar10

But ah well...
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17101871
Depending on what you are trying to achieve, there may be alternatives to using properties. If you wanted a large number of properties but not have to create variables for each one then you could opt for exposing a HashTable via a property and that would then allow your users to add Name/Value pairs through a single property.

This, of course, would require a little more validation within the property itself to make sure the user doesn't add anything they shouldn't. You could even have a method called SetProperty that takes a property name or Enum and a value:

    Private _hash As New HashTable()

    Public Sub SetProperty(ByVal name As String, ByVal value As String)
 
        _hash[name] = value

    End Sub
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17101902
Beyond my 'current' understanding - but thanx.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question