Custom Class Objects in VBScript - Adding properties to a class
(Page 3 of 4 )
You can set the permission level on properties and methods inside of a class. For our purposes, we’ll be setting them as either Private or Public. Private properties and methods are only available to code within the class itself. Public properties and methods are available to outside scripts and applications, and are exposed through the class object.
Properties and Methods are exposed through an object Interface. With VBScript classes, these interfaces are created automatically for you.
There are two types of properties in VBScript: Read/Write and Read-only. A read/write property allows you to retrieve the property's current value or assign one. A read-only property will only allow you to retrieve the current value.
Properties are created using a Property structure. There are three types of property structures: Property Get, Property Let, and Property Set. Property Get is used to create a class property. This is the structure that will Get or return the current property value. Property Let is the counterpart; it accepts a parameter and allows the programmer to pass a value to be assigned to the property. The Property Set structure is the same as Property Let, but it is used when a Property is being assigned an object value.
All properties must have a Property Get block. Properties that only have a Property Get block are treated as Read-only. Properties that add either a Property Let or Property Set block are treated as Read/Write.
A property is only required to have a Property Get structure. Property Let and Property Set can be omitted if the property is to be treated as read-only. You may also want to consider the fact that properties do not need to be made Public. Private properties would only be available from inside the class itself. I can’t think of a reason to do this myself, but I thought I’d at least mention it.
Class CompressedFolder
Private m_fileName
Public Property Get FullName
FullName = m_fileName
End Property
Public Property Let FullName(strName)
m_fileName = strName
End Property
Public Property Get Path
Path = Left(FullName, InStrRev(FullName, ""))
End Property
End Class
Next: More on adding properties >>
More Code Examples Articles
More By Nilpo