Question properties conversion from VB6

snoopy123123

Member
Joined
Jun 24, 2013
Messages
6
Programming Experience
5-10
Hello,

I am very new to VB.net coming mainly from Delphi. However I have been thrown on a project to convert VB6 code to VB in VS2010.net and I am struggeling with with properties. How would I convert the following VB6 code into .net ? The whole Let/Get thing gets me confused right now so every explanation would be appreciated. Thanks in advance.

Public Property Let Coat(ByVal vData As String)
mvarCoat = vData
End Property

Public Property Get Coat() As String
Coat = mvarCoat
End Property







Property


 
Hi,

In .NET the VB6 Get and Let commands are replaced with Get and Set so the .NET equivalent of your code is:-

VB.NET:
Private _Coat As String
 
Public Property Coat As String
  Get
    Return _Coat
  End Get
  Set(value As String)
    _Coat = value
  End Set
End Property

In the above example I have explicitly coded the Get and Set methods of the property and when you do so you must declare a Private variable to hold the value of the property internally. Doing things this way allows you to code other things that you may want to happen when a property is either Set or Retrieved.

If you do not require any other code to be executed when a property is used then you can just declare the property as:-

VB.NET:
Public Property Coat As String

In this case the .NET system automatically creates an internal variable in the form of "<underscore>YourPropertyName" to store the contents of the property. i.e:-

VB.NET:
_YourPropertyName

Hope that helps.

Cheers,

Ian
 
Last edited:
Hi,


If you do not require any other code to be executed when a property is declared then you can just declare the property as:-

VB.NET:
Public Property Coat As String

Oh so this one Line of code replaces the get and set part if there is no code executed ? That's nice. Thank you.
 
Back
Top