SunQuest
 
       Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - Understanding Objects
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Understanding Objects
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 4
    2008-02-12

    Table of Contents:
  • Understanding Objects
  • What objects provide
  • How COM objects are built
  • More about objects

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Understanding Objects - What objects provide


    (Page 2 of 4 )

    Objects typically offer three types of data or code to a script.  They may use any or all of these three types.  They include:

    • Methods – These are code procedures that perform specific tasks.  They are generally in the form of subroutines and functions.
    • Properties – These are in a sense variables.  They represent a stored value.  This value may be retrieved or set dependent upon whether or not the property is read-only.
    • Events – These are special hook and sink strategies that are used to notify other code when a specific event has taken place.  Code can be written to react to these events.

    These data types must be exposed explicitly by the class in order to be used publicly.  Let’s take a look at the Shell Automation Service object as an example.  This is a COM object that allows you to interact with the Windows shell.  Before you can use it, it must be referenced, or instantiated, in your code.  VBScript and Jscript each do this differently.

    VBScript:

    Set objShell = CreateObject("Shell.Application")

    Jscript:

    var ShellObject = new ActiveXObject("Shell.Application");

    VBScript’s CreateObject function and Jscript’s ActiveXObject function both return an object reference that must be assigned a variable name.  You indicate which object you would like to instantiate by specifying its namespace.  This is a unique identifier that follows the COM naming convention.

    Objects may also contain sub-objects.

    Once an object has been instantiated, you can use its reference to access any exposed properties and methods.  In OOP, or object-oriented programming, this is done with dot syntax.  The remaining examples in this article will be written in VBScript.

    Set objShell = CreateObject("Shell.Application")

    objShell.MinimizeAll

    In the example above we’re calling the MinimizeAll method of the Shell object to minimize all open windows.  Notice that dot syntax is being used: object.method.

    Set objFso = CreateObject("Scripting.FileSystemObject")

    Set colDrives = objFso.Drives

    intNum = colDrives.Count

    In this example, we’re using the FileSystemObject’s Drives property to return a collection of drives.  This is a sub-object of the FileSystemObject.  We then use its Count property to return the number of sub-objects that it contains.

    In VBScript and WSH, some objects do not require instantiation.  They are made available by the environment.  Two examples are the WScript object, which references the currently active WSH session, and VBScript’s Err object, which references the Standard Error output stream.

    Because these objects are made available by the environment, they can be accessed immediately without first connecting to them or assigning them to variables.  You can see both in use in the following example.

    WScript.Echo WScript.FullName

     

    If Err.number <> 0 Then

       WScript.Echo "There was an error."

     

    End If

    Notice that there was no need to include any Set statements.  Instead, we are able to begin using properties and methods from these objects immediately.

    More Windows Scripting Articles
    More By Nilpo


     

    WINDOWS SCRIPTING ARTICLES

    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications
    - Securing Computers and Active Directory




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway