Coding a Custom Object with WSC
(Page 1 of 5 )
In the previous tutorial of this series we used the Windows Component Wizard to create our own custom COM object file. We told the wizard how we wanted it configured and it output the basic XML file for us. Now it’s time to put some code into that file.Our object exposes some properties and methods, but it doesn’t actually
do anything yet. For that we need to add some scripting. I’m not going to go into detail about how this code works exactly; you can just cut at paste it into the <script> section. Make sure that the code is between the <![CDATA[ and the closing ]]>. This is a method of commenting text in an XML file. The file will not parse properly if this isn’t present.
Dim FullName
Dim Name
Dim Path
Dim Count
Function get_FullName()
get_FullName = FullName
End Function
Function put_FullName(newValue)
FullName = newValue
End Function
Function get_Name()
get_Name = Right(FullName, Len(FullName) - InStrRev(FullName, ""))
End Function
Function get_Path()
get_Path = Left(FullName, InStrRev(FullName, ""))
End Function
Function get_Count()
get_Count = GetItemCount(FullName)
End Function
First things first. We define a few variables to hold the property values in our script, and then we provide the necessary functions for retrieving and setting those property values. Notice the special syntax that is used in naming these functions. They begin with either “get” or “put” followed by an underscore, and then the name of the property as defined in the <public> section from earlier.
The get function is called whenever an outside script requests the value of a property. The put function is called whenever an outside script passes a value to be assigned to the property. You may or may not need either or both of these functions, depending upon whether the property is read-only, write-only, or read-write.
Next: Adding code for the object methods >>
More Code Examples Articles
More By Nilpo