Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Usage value of properties
#1
Hi, I have a little question here

I'm using a lot of properties but I don't know what value to use in my other subs. I find it hard to explain so I have an example:

[code2=vbnet]'This is the property itself
Private _TextCancelButton As String = "Cancel"
<Category("TextFields"), Description("The text shown in the Cancel button"), DefaultValue("Cancel")>
Public Property TextCancelButton() As String
Get
Return _TextCancelButton
End Get
Set(value As String)
_TextCancelButton = value
cmdCancel.Text = _TextCancelButton
End Set
End Property[/code2]

Now what should I use know to change the text of the Cancel button, for example when another button is clicked?

[code2=vbnet]cmdCancel.Text = _TextCancelButton
'or
cmdCancel.text = TextCancelButton[/code2]


I think it is the same, or not?

Thanks, Brecht
#2
Well, as you can see, one is a private variable (_TextCancelButton), and the other is a public property (TextCancelButton).

Because of this, you should use _TextCancelButton whenever you are referring to the variable within the class that contains the variable. For example, if _TextCancelButton is located in the code for Form1, only use _TextCancelButton in Form1's code.

If you're in any other class, use the TextCancelButton property.

I hope this helps!
My Blog | My Setup | My Videos | Have a wonderful day.
#3
My opinion is that changing the property itself should do just fine no need to complicate things

[code2=vbnet]TextCancelButton = "text here"[/code2]
Sssssssssoftware developer...


Possibly Related Threads…
Thread Author Replies Views Last Post
  Properties for UserControl brco900033 4 16,909 04-27-2013, 05:01 AM
Last Post: brco900033

Forum Jump:


Users browsing this thread: 1 Guest(s)