BP Forums
Usage value of properties - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8)
+----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=9)
+----- Thread: Usage value of properties (/showthread.php?tid=809)



Usage value of properties - brco900033 - 08-31-2013

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


Re: Usage value of properties - brandonio21 - 09-02-2013

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!


Re: Usage value of properties - Snake_eyes - 09-11-2013

My opinion is that changing the property itself should do just fine no need to complicate things

[code2=vbnet]TextCancelButton = "text here"[/code2]