A property, also called field or attribute, characterizes a given object or piece of information. Properties can be used to control access to data. It is common use to include instructions at setting or reading time of properties. Code can vary from simple assignment to complex context dependent routines. Using Get, Let or Set accessors enforces properties' consistency when necessary.This statement requires Option Compatible to be placed before the executable program code in a module. Property Get Statement diagram[Private | Public] Property Get name[char | As typename]End PropertyProperty Set Statement diagram[Private | Public] Property [Let | Set] name[char] [([Optional [ByRef | ByVal]]value[char | As typename])] [As typename]End Propertyname: The property name.argument: Value to be passed to the Property setter routine.Property setters often use a single argument. Multiple arguments are equally accepted.
Examples
Option CompatibleSub Main ProductName = "Office" Print ProductName ' displays "%PRODUCTNAME"End SubPrivate _office As StringProperty Get ProductName As String ProductName = _officeEnd PropertyProperty Let ProductName(value As String) _office = "Libre"& valueEnd PropertyIn the absence of Property Let or Property Set, Property Get helps define protected information, which can not be accidently altered by a foreign module:Option CompatiblePublic Property Get PathDelimiter As String ' Read-only variable Static this As String If this = "" Then : Select Case GetGuiType() Case 1 : this = ";" ' Windows Case 4 : this = ":" ' Linux or macOS Case Else : Error 423 ' Property or method not defined: PathDelimiter End Select : End If PathDelimiter = thisEnd Property ' read-only PathDelimiterSub Main PathDelimiter = "a sentence" ' does nothingEnd SubUse Let or Set when handling UNO services or class objects:Option CompatibleSub Main 'Set anObject = CreateUnoService( "com.sun.star.frame.Desktop" ) anObject = CreateUnoService( "com.sun.star.frame.Desktop" ) Print anObject.SupportedServiceNames(0) ' displays "com.sun.star.frame.Frame"End SubProperty Get anObject As Object Set anObject = _objEnd PropertyPrivate _obj As Object'Property Set anObject(value As Object) 'Set _obj = value.CurrentFrame'End PropertyProperty Let anObject(value As Object) Set _obj = value.CurrentFrameEnd PropertySubroutines basicsEnd, Exit statements