Get Statement
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Get Statement

Declares a Get property procedure used to retrieve the value of a property.

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


Optional. List of attributes that apply to this Get block. Multiple attributes are separated by commas.
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

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


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.


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 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

© 2016 Microsoft