fb

Ads

Pages

Creating Properties [VB.net]

 Creating Properties [VB.net]


You can now start adding properties to your class, but be aware that the syntax for creating Visual properties has changed.
Add a FirstName property by first creating a private variable. Inside the class, add the following code:


Dim msFirstName as String


Now, add the following code. Realize that as soon as you type the first line, most of the rest of the code will be filled in for you by the IDE. You’ll still have to add the Return and the assignment.


Public Property FirstName() As String
Get
Return msFirstName
End Get
Set(ByVal Value As String)
msFirstName = Value
End Set
End Property


Notice the new syntax for creating properties. No longer do you create matching Public Property Get/Public Property Let procedures. Instead, you create a Public Property block and then add a Get and a Set section to it. There is no Let anymore, which makes life easier.
Also notice that this property does not accept an argument, as you would have had to do with a Public Property Let in VB6. This means that you no longer have to have the value passed in as a parameter; instead, if the user passes in a value, it is put in the Value variable automatically.

2 comments:

Thanks for all the great work . I have always admired this site and your work ..
Website Design Services Dubai

Thanks for you great post.
http://www.candlelightdubai.com/

Post a Comment