Export (0) Print
Expand All
11 out of 17 rated this helpful - Rate this topic

Displaying Data by Using Internet Explorer

Microsoft® Windows® 2000 Scripting Guide

By using the various string manipulation functions found in VBScript, you can display data in tabular format within the command window. This makes the data easier to analyze but only partly compensates for the limitations found in the command window. For example, no VBScript function lets you use multiple fonts and multiple colors within the command window. Likewise, no VBScript method lets you easily print data from within the command window. Instead, you must copy the entire data set (assuming that the data does not exceed the command window display buffer), paste the data into another application, and then print the data.

If you prefer to use formatting that goes beyond a tabular display or if you would like the ability to print the returned data, you might consider outputting information to Internet Explorer rather than the command window. Unlike the command window, Internet Explorer lets you use multiple fonts and multiple colors; you can even include graphics within your output. In addition, you can use the Print function of the browser to print the data, without having to copy and paste it into another application.

In the examples that follow, you do not create a Web page (that is, an .asp file). Instead, you use VBScript to instantiate an instance of Internet Explorer, and you then use VBScript commands to control that instance of the browser. This is possible because Internet Explorer provides an Automation object model that can be controlled from within a script. You can use this object model to create an instance of Internet Explorer and then do such things as:

  • Configure the user interface (for example, hide or display the address bar or set the window size).

  • Open a specific file or navigate to a specific URL.

  • Dynamically show or hide the browser window based on specified conditions.

  • Write data to the page displayed in the browser window.

In fact, nearly all the functionality of Internet Explorer is exposed through the Automation object model. Some of the properties and methods especially useful to script writers are shown in Table 17.3.

Table 17.3 Internet Explorer Properties and Methods

Property/Method

Description

Application

Used with the CreateObject method to return an instance of Internet Explorer. For example:Set objExplorer = _ CreateObject("InternetExplorer.Application")

Busy

Returns a Boolean value indicating whether Internet Explorer is still loading or performing some other activity. This is often used at the start of a script to ensure that Internet Explorer is fully loaded before any other script actions take place. Your script might check the Busy status and, if True, pause for a specified amount of time and then check again. As soon as Busy is False, the script can proceed.

For example:

FullScreen

Boolean value that sets the Internet Explorer window mode. If True, the window is maximized, and the status bar, toolbar, menu bar, and title bar are hidden.

Height

Sets the height of the Internet Explorer window in pixels.

Width

Sets the width of the Internet Explorer window in pixels.

Left

Sets the position of the Internet Explorer window relative to the left side of the screen. For example, this command positions the window 200 pixels from the left side of the screen:objExplorer.Left = 200

Top

Sets the position of the Internet Explorer window relative to the top of the screen. For example, this command positions the window 100 pixels from the top of the screen:objExplorer.Top = 100

MenuBar

Toggles the display of the menu bar on or off. If 0, the menu bar is not visible; if 1, the menu bar is displayed.

StatusBar

Toggles the display of the status bar on or off. If 0, the status bar is not visible; if 1, the status bar is displayed.

StatusText

Sets the text in the status bar.

ToolBar

Toggles the display of the toolbar on or off. If 0, the toolbar is not visible; if 1, the toolbar is displayed.

Visible

Determines whether Internet Explorer is visible on the screen. Any instance of Internet Explorer you create will not be visible until you set this property to 1. To hide a running instance of Internet Explorer, set the value to 0.

Navigate

Loads the specified document in the Internet Explorer window.

To load a blank document

Set the property to "about:blank". For example:

ObjExplorer.Navigate "about:blank"

To load a file

Specify the file name, prefacing the path with the file:// designator. For example:


ObjExplorer.Navigate "file://c:\scripts\service_data.asp
"

To load a Web page from a URL

Specify the URL, prefacing the path with the http:// designator. For example

Quit

Closes Internet Explorer and terminates the object instance.

Refresh

Updates the Internet Explorer instance.

Internet Explorer also exposes several other objects that let you not only control the behavior of the browser but also dynamically control the contents of the browser window. For example, you might create an instance of Internet Explorer and open a blank Web page. You can then use the Document object to dynamically change the contents of that Web page.

This has nothing to do with creating pages for the World Wide Web. In fact, you still create files with the .vbs file name extension; you do not create Web pages with the .asp file name extension. Instead, you use a script to open Internet Explorer and then use a combination of scripting code and HTML tags to redirect the script output to the browser window.

Creating an Instance of Internet Explorer

You can use Internet Explorer as a display device by creating an instance of the browser and then issuing the appropriate commands to:

  • Configure the user interface.

  • Navigate to the desired pages.

  • Write information to the document that is currently loaded.

To create an instance of Internet Explorer, use the CreateObject method and the ProgID InternetExplorer.Application. For example, this line of code creates an instance of Internet Explorer and assigns it to the object variable objExplorer:



Set objExplorer = CreateObject("InternetExplorer.Application")

After the object has been created, you can control it by using the object variable assigned to that instance of Internet Explorer. For example, this command will hide the toolbar:



 objExplorer.ToolBar = 0

Any commands you issue will affect only the instance of Internet Explorer you created. If you have multiple copies of the browser running, a command to hide the toolbar will hide only the toolbar in the instance of Internet Explorer under the control of your script. The toolbar will remain visible in any other instances of Internet Explorer that are running.

Scripting Steps

Listing 17.6 contains a script that creates an instance of Internet Explorer. To carry out this task, the script must perform the following steps:

  1. Create an instance of Internet Explorer.

  2. Use the Navigate method to open a blank Web page.

    This is done by using "about:blank" as the method parameter. You can also open a URL or a file by passing the appropriate path to the Navigate method. For example, you can open the file C:\Scripts\Service_data.asp by using this code:

    
    
    objExplorer.Navigate "file://c:\scripts\service_data.asp"
    
    
  3. Configure various Internet Explorer properties, such as the height and width of the window, and hide items such as the toolbar and status bar.

  4. Set the Visible property to 1 to display the instance on the screen. Internet Explorer will not appear on the screen unless you set the Visible property to 1.

Listing 17.6 Creating an Instance of Internet Explorer

  
1
2
3
4
5
6
7
8
9


Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 300
objExplorer.Height = 150
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Visible = 1

When the script in Listing 17.6 is run, you will see a blank Web page similar to that shown in Figure 17.1.

Figure 17.1 A Blank Web Page in Internet Explorer

sas_ent_04s.gif

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.