VBS TUTORIAL: function-getobject function _vbs

Source: Internet
Author: User

GetObject function

Returns a reference to the Automation object in the file.

GetObject([pathname] [, class])

Parameters

Pathname

Options available. A string that contains the full path and name of the file to retrieve the object. If you omit pathname , you must have class.

Class

Options available. String, the class of the object.

The syntax format for the class parameter is appname.objectype, which includes the following sections:

Parameters

AppName

Required option. A string that provides the application name of the object.

Objectype

Required option. A string that is the type or class of the object to create.

Description

You can use the GetObject function to access the Automation object in the file, and you can assign the object to an object variable. Use the Set statement to assign an object returned by GetObject to an object variable. For example:

Dim CADObject
GetObject("C:\CAD\SCHEMA.CAD")

When the above code is executed, the application associated with the specified path name is started, and the object in the specified file is activated. If pathname is a 0-length string (""),GetObject Returns a new object instance of the specified type. If the pathname argument is omitted,GetObject Returns the currently active object of the specified type. If you do not have an object of the specified type, an error occurs.

Some applications allow only part of the file to be activated by adding an exclamation point (!) to the file name and a string that identifies the part of the file to be activated. For more information about creating such a string, see the documentation for the application that created the object.

For example, in a drawing application, a diagram stored in a file might have multiple layers. You can use the following code to activate the diagram SCHEMA. One of the layers in CAD:

GetObject("C:\CAD\SCHEMA.CAD!Layer3")

If no class is specified for the object, Automation determines the application to start and the object to activate, based on the file name provided. However, some files may support multiple object classes. For example, a diagram might support three different types of objects: application objects, Drawing objects, and Toolbar objects, all of which are part of the same file. Use the optional class parameter to specify the object to be activated in the file. For example:

Dim MyObject
GetObject("C:\DRAWINGS\SAMPLE.DRW", "FIGMENT.DRAWING") 

In the example above, Figment is the name of the drawing application, and DRAWING is one of the object types it supports. After an object is activated, you can use the defined object variable to reference it in code. In the previous example, you can use the object variable MyObject to access the properties and methods of the new object. For example:

MyObject.Line 9, 90
MyObject.InsertText 9, 100, "Hi, Hello!"
MyObject.SaveAs "C:\DRAWINGS\SAMPLE.DRW"

Note Use the GetObject function when the current instance of an object exists, or when you want to create an object with a loaded file. If there is no current instance and you are not ready to start the object with the loaded file, use the createobject function.

If an object is registered as an object of a single instance, only one instance of the object can be created, no matter how many times the CreateObjectis executed. With a single instance object, when invoked with a 0-length string ("") syntax,GetObject always returns the same instance, and if the pathname argument is omitted, an error occurs.

Copy Code code as follows:

Set ODOM = wscript.getobject (wscript.arguments (0))
Do Until Odom.readystate = "complete"
Wscript.Sleep 200
Loop
WScript.Echo ODOM.documentElement.outerHTML

Or
Copy Code code as follows:

Set odom=wscript.getobject ("http://www.ip138.com/ip2city.asp") ' is to get this object
Do Until odom.readystate= "complete" wait 200ms until the page is loaded
Wscript.Sleep 200 ' is waiting for 200ms
Loop
WScript.Echo ODOM.documentElement.outerText ' Get a text and pop up a dialog box to display this message
Set odom=nothing ' disconnects from the object to free memory.

More can refer to:
Http://www.jb51.net/shouce/vbs/115.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.