Visual Basic Language Reference  

Get Statement

Declares a Get property procedure used to assign a value to a property.

[ <attrlist> ] Get()
   [ block ]
End Get

Parts

attrlist
Optional. List of attributes that apply to this Get block. Multiple attributes are separated by commas.
block
Optional. The body of the Get property procedure contains code to return the property value.
End Get
Terminates a Get property procedure.

Each attribute in the attrlist part has the following syntax and parts:

attrname [({ attrargs | attrinit })]

attrlist Parts

attrname
Required. Name of the attribute. Must be a valid Visual Basic identifier.
attrargs
Optional. List of positional arguments for this attribute. Multiple arguments are separated by commas.
attrinit
Optional. List of field or property initializers for this attribute. Multiple initializers are separated by commas.

Remarks

Get property procedures can return a value using either the Return keyword or by assigning the return value to the property where the get procedure is declared. The value returned by a Get property procedure is usually a private class level variable that stored the property value after a property set operation.

Example

This example uses the Get statement to return the value of a property.

Class PropClass
   ' Define a local variable to store the property value.
   Private CurrentTime As String
   ' Define the property.
   Public ReadOnly Property DateAndTime() As String
      Get
         ' Get procedure is called when the value
         ' of a property is retrieved. 
         CurrentTime = CStr(Now) 
         Return CurrentTime    ' Returns the date and time As a string.
      End Get
   End Property
End Class

See Also

Set Statement | Property Statement