Low cost ecommerce web development India flash website design
COM is the standard for the interface to
objects. By definition, COM objects have only methods and properties; there
are no other interfaces. There isn't much difference between properties and
methods from a programmer's standpoint: Methods can take arguments,
properties can't. Properties can be read/write; methods - if they return a value
- are read-only.
Component designers use methods and properties for different functionality.
Properties usually represent some aspect of the object's state, whereas a
method can be a function that performs regardless of whether the object's
state is involved.
Properties
Properties do not take any arguments and are usually used to describe or set
the state of an object. All properties return a value, however some properties
are read-only, and some are read/write. Here is an example of the VBScript
syntax for reading a property:
67
value = object.property
Note there are no parentheses, not even a blank set; that is, (). Here is the
Visual Basic syntax for setting a property:
object.property = value
Methods
Methods can return values and take arguments. They are most often used to
initiate an event within the object. Methods can be used to set values, but
only when passing the value through the argument list. If a method returns a
value but doesn't take an argument, the syntax will be:
value = object.method()
Note that the method has a set of blank parentheses. Methods that have a
return value must have arguments encapsulated in parentheses. For example,
the Connection object has an Execute method that returns a RecordSet
object. Here is an example:
Set RS = Conn.Execute(“SELECT * FROM TABLE”)
Methods that do not return values do not have parentheses around the
arguments. For example, the Close method of the Connection object is not
encapsulated in parentheses:
Conn.Close
Arguments
Methods can take one or more arguments, or take none at all. However,
arguments might be optional. If they are, you do not have to enter anything
for an argument. Once one argument is optional, all arguments following it
are also optional. For example, if arguments one and two are required, and
three is optional, argument four has to be optional. A good example of an
optional argument method is the Open method of the Connection object.
The Open method has eight optional arguments. The first three are for
establishing the database and the logon information.
Conn.Open “DSN”,”sa”,””
This indicates a DSN of “DSN”, a logon of “sa”, and a password of “”.You
can also call the Open method as:
68
Conn.Open "driver=SQL
Server;server=yourServerName;uid=someUID;pwd=somePWD;database=
someDatabase;"
Calling the arguments by delimiting with the argument and leaving it blank
causes the method to execute with nulls instead of the optional argument's
default values.
Conn.Open “DSN”,”sa”,””, , , ,
This calls the optional methods with null values, which is different than
earlier.
Collections
Collections are objects that represent a set of objects. All collections have
predefined methods and properties. A collection object has an Item method,
a Count property, and a _NewEnum method. A collection can also create
objects of the collection type. In other words, if a particular object can be
grouped in a set, that object will have a collection object that can create an
instance of an object within the set. For example, a Drives collection object
will contain a set of drives that can represent all the drives on a particular
computer.
The Count property returns a LONG value that specifies how many objects
are in the collection. By passing a LONG value - that is between one and the
value returned by the Count property -- to the Item method, the collection
method will return the object in the set that is associated with that position.
Accessing an item in an array works similarly.
The _NewEnum method enables a programmer to iterate through the
collection in a For…Next statement.
For Each Object in Collection
...
Next Object
Note that the _NewEnum method is not referenced within the syntax of the
statement in Example 6. This is because the _NewEnum method has a
special index that is used for the For…Next statement. In fact, all methods
and properties in a COM object are indexed and certain indexes are used for
particular tasks. For example, the zero index is used for the default method or
property.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73