Custom Class Objects in VBScript - More on adding properties
(Page 4 of 4 )
I’ve begun constructing my class by adding some properties. Notice how the Property structures look like functions that are executed when a property is retrieved or assigned. Immediately inside of my class I’ve created a few private variables. These are global variables that I’ll be using throughout my class to track the value of the properties.
In this example, I’ve added two properties. The FullName property has both Get and a Let, so it is a Read/Write property. The Path property only has a Get structure, so it is a Read-only property. These properties could now be used in my script.
Set objZipFolder = New CompressedFolder
WScript.Echo objZipFolder.FullName
objZipFolder.FullName = "My new FullName value"
WScript.Echo objZipFolder.Path
Here is the complete property listing for the CompressedFolder class.
Class CompressedFolder
Private m_fileName
Public Property Get FullName
FullName = m_fileName
End Property
Private Property Let FullName(strName)
m_fileName = strName
End Property
Public Property Get Filename
Filename = Right(FullName, Len(FullName) - InStrRev(FullName, ""))
End Property
Public Property Get Path
Path = Left(FullName, InStrRev(FullName, ""))
End Property
Public Property Get Count
Count = GetItemCount(FullName)
End Property
End Class
Having a few properties doesn’t do much for this class. We need a way to create the compressed folder and to manipulate it. For that we need to add some methods. These are the functions and subroutines that perform the magic when the class is called. For that, you’ll also need to wait for part two of this series! Until next time, keep coding!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |