Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Schongar P.VBScript unleashed.1997

.pdf
Скачиваний:
43
Добавлен:
23.08.2013
Размер:
1.59 Mб
Скачать

Saving and Recalling RTF Documents

Review

Chapter 27 The Chart and Grid Controls

The Chart Example

The GridChart Example

The Grid Control

Implementing the Application

Review

Appendix A VBScript Language Reference

Variables, Constants, and Expressions

Operators

Arithmetic Operators

Concatenation Operators

Logical Operators

Comparison Operators

Statements

Functions

Variable and Conversion Functions

Date/Time Functions

Conditional Functions

String Functions

Input Functions

Mathematical Functions

Credits

Copyright © 1997 by Sams.net Publishing

FIRST EDITION

All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein. For information, address Sams.net Publishing, 201 W. 103rd St., Indianapolis, IN 46290.

International Standard Book Number: 1-57521-124-6

HTML conversion by :

M/s. LeafWriters (India) Pvt. Ltd.

Website : http://leaf.stpn.soft.net

e-mail : leafwriters@leaf.stpn.soft.net

Trademarks

All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams.net Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.

VBScript is a trademark of Microsoft Corporation.

Publisher and President:

Richard K. Swadley

Publishing Manager:

Greg Wiegand

Director of Editorial

Cindy Morrow

Assistant Marketing

Kristina Perry, Rachel Wolfe

Services:

 

Managers:

 

Acquisitions Editor

Christopher Denny

Development Editor

Anthony Amico

Software Development

Brad Myers

Production Editor

Mary Inderstrodt

Specialist

 

 

 

Copy Editors

Heather Butler, Keith

Indexer

Johnna VanHoose

 

Davenport, Karen

 

 

 

Letourneau

 

 

Technical Reviewer

Greg Guntle

Editorial Coordinator

Katie Wise

Technical Edit

Lynette Quinn

Resource Coordinator

Deborah Frisby

Coordinator

 

 

 

Editorial Assistants

Carol Ackerman, Andi Richter, Rhonda Tinch-Mize

 

Cover Designer

Gary Adair

Book Designer

Gary Adair

Copy Writer

Peter Fuller

Production Team

Brad Chinn

 

 

Supervisor

 

Production

Sonja Hart, Michael Henry, Timothy Osborn, Gene Redding

 

About the Authors

Bill Schongar and Paul Lagasse are the Senior Multimedia Developers at LCD Multimedia Creations, Inc., in Nashua, NH (bills@lcdmultimedia.com and paull@lcdmultimedia.com). Paul is an experienced Visual Basic

programmer, with a design background that he's having fun putting to use in a variety of online endeavors. Bill somehow ended up in the computer industry, learning and teaching things about the online world, and contributing to other books such as CGI Programming Unleashed. Just don't ask Paul to recommend any movies, or Bill to show you how to juggle axes.

Evangelos Petroutsos has a M.S. degree in Computer Engineering and works as a freelance writer and consultant. He is the author of Interactive Web Publishing with Microsoft Tools and co-author of Visual Basic Power Toolkit.

Craig Eddy resides in Richmond, VA, with his wife and two children. Craig holds a B.S. in Electrical Engineering from Virginia Tech. He is currently employed as Senior Developer for Pipestream Technologies, Inc., where he is responsible for the continuing development of ContactBuilder and Sales Continuum. He is also the architect and chief programmer for the two-way synchronization between SQL Server and remote versions of Pipestream's sales force automation products. Craig specializes in Visual Basic, SQL Server, and Access development. He has been an author for Access 95 Unleashed and Office 95 Unleashed, as well as being co-author of Web Programming with Visual Basic. Craig's hobbies include private business development and relaxing at the Outer Banks in North Carolina. Craig can be reached at craige@richmond.infi.net.

Keith Brophy is the Software Release Coordinator at X-Rite, Incorporated, and has had many years of experience in the design, development, and testing of software systems. In addition, he has taught advanced programming courses both at

Grand Rapids Community College and Northern Virginia Community College. Keith has tech edited Real-World

Programming with Visual Basic and co-authored Visual Basic 4.0 Performance Tuning and Optimization and Teach Yourself Visual Basic Script in 21 Days, both from Sams.

Owen Graupman has been working as a system integrator for various firms since he entered the workforce. A programmer by trade, he's written many custom financial applications using Visual Basic. He is currently employed as an independent consultant based in Los Angeles, California.

Brian Johnson is a freelance writer and programmer in Orlando, Florida. He has been involved in Internet development and Visual Basic programming for more than three years. You can usually find him answering questions in the Microsoft ActiveX newsgroups or find out more about him by hitting his Web site at http://home.sprynet.com/

sprynet/bjjohnson.

Timothy Koets is a software engineer at X-Rite, Incorporated. He has extensive experience with Visual Basic, VBScript and Web Page development. He is currently teaching Advanced Visual Basic at Grand Rapids Community College. He also has experience with Visual C++, Delphi, Java, PowerBuilder and Lotus Notes. Timothy is the co-author of Visual

Basic 4.0 Performance Tuning and Optimization and Teach Yourself Visual Basic Script in 21 Days, both from Sams.

Tell Us What You Think!

As a reader, you are the most important critic and commentator of our books. We value your opinion and want to know what we're doing right, what we could do better, what areas you'd like to see us publish in, and any other words of wisdom you're willing to pass our way. You can help us make stronger books that meet your needs and give you the computer guidance you require.

Do you have access to CompuServe or the World Wide Web? Then check out our CompuServe forum by typing GO SAMS at any prompt. If you prefer the World Wide Web, check out our site at http://www.mcp.com.

NOTE

If you have a technical question about this book, call the technical support line at (800) 571-5840, ext. 3668.

As the publishing manager of the group that created this book, I welcome your comments. You can fax, e-mail, or write me directly to let me know what you did or didn't like about this book-as well as what we can do to make our books stronger. Here's the information:

FAX: 317/581-4669

E-mail: programming_mgr@sams.mcp.com

Mail: Greg Wiegand

Sams.net Publishing

201 W. 103rd Street

Indianapolis, IN 46290

Chapter 1

Introducing HTML Scripting

by Brian Johnson

CONTENTS

Introduction

Designing Web Pages

Definitions

First Things First-HTML

The <HEAD> Tag

The <TITLE> Tag

The <BODY> Tag

Headings

Paragraphs

The <FONT> Tag

Links in Your Documents

Graphics

Multimedia in HTML

Tables

Forms in HTML

Using CGI Scripts in HTML

Other HTML Tags

Frames

Scripting

Objects

ActiveX Controls

Review

Introduction

To understand VBScript, you should first have a fairly good understanding of Hypertext Markup Language (HTML). If you are already well versed in HTML, you can probably skim this chapter. We'll start to get into the details of the VBScript language in Chapter 2 "The VBScript Language."

In this chapter, you will

Learn about active Web pages

Review concepts that you should be familiar with

Get a quick tutorial on HTML

Learn about objects in your HTML pages

Learn about ActiveX controls on the World Wide Web

Designing Web Pages

There are too many important facets to the language of the World Wide Web to say that any one is the most important. That language is called HTML. In the years since its inception, the HTML specification has been fairly dynamic. So far, each feature added to the standard has made HTML better. Succeeding specifications make pages more attractive, more informative, and richer in content-so much so that Web pages are quickly becoming the interface of choice for retrieving information from computer screens.

This book is about a scripting language called VBScript. VBScript is used to control content and objects in HTML pages designed for the World Wide Web and corporate intranets. VBScript is not about creating applications; it's about creating active HTML. If your pages look and work like applications, that's fine. The most important thing that you're doing when you're using VBScript in your Web pages is bringing the pages to life. Dead, static pages on the Web are about as exciting as slides on television. In the future, pages will be designed on the fly, tailored to the profile of the individual user.

Definitions

If you're new to creating content for the World Wide Web, there are a few concepts that you should be familiar with. The first is the URL, or Uniform Resource Locator. The URL is the address of a particular item on the Internet. This address can be part of either a domain name or an IP (Internet Protocol) address. A URL using a domain name would look something like www.microsoft.com, and the file you're looking for might be in the directory /vbs. You can just as easily use the IP address to get the file you're looking for. For the address www.microsoft.com, the numbers would be 198.105.232.5. A complete URL contains a protocol prefix, such as http:// or ftp://, followed by the address and a port number-for example, http://www.microsoft.com:80.

The second concept that you should understand is client/server. The server is a machine that contains the content and the associated server software. The client is a machine that is usually not a server but that connects to the server to retrieve content. In this book, you'll read a lot about what's happening on the server side versus what's happening on the client side. In the case of the World Wide Web, the server is the machine that contains your published Web pages, and the client machines are those of people who are viewing your pages.

The final concept that you should be familiar with is bandwidth. Bandwidth determines speed at which you can move an amount of data between machines. Three broad types of bandwidth exist: low bandwidth, middleband, and broadband. Low-bandwidth connections are analog connections with modems. Analog connections use sounds that must be translated into digital signals before a machine can understand them. A middleband connection might be an ISDN or other digital connection. Digital connections are faster because they require no translation step, and the signal itself is usually cleaner. A broadband connection might be a T1 connection or a cable modem. Right now, most client machines hook into the Internet in the low-bandwidth connection range. Over the next few years, middleband and broadband connections will become much more common. This should open up great opportunities for you as a content author.

First Things First-HTML

Scripting is about controlling objects. In the same way that a movie script helps to determine what actors do and say, the scripts that you write to control your HTML pages are plans for what the objects in your pages will do. To start, let's quickly review HTML.

HTML isn't really a computer language in the strictest sense of the term. For the most part, HTML is a page-description language that determines how a page will look on the screen.

The page defined in Listing 1.1 and shown in action in Figure 1.1 can be described as static, because it doesn't do too

much. It can take you somewhere else, but the point of designing pages isn't so much to send someone somewhere else (although half the Web probably does that). You design a page so that people will come to the page and stick around for a while. You want to distribute information, you want to entertain, and most importantly you want your page to be worthy of a link on someone else's page.

Figure 1.1 : Listing 1.1, as viewed from Internet Explorer.

Listing 1.1. A basic HTML page.

<HTML><HEAD>

<TITLE>Basic HTML Page</TITLE>

</HEAD>

<BODY>

<H1>This is a level 1 Heading</H1>

<BR>

This is a <A HREF="HTTP://WWW.MICROSOFT.COM/">hyper-link</A> to Microsoft.

</BODY>

</HTML>

Scripting can help to make this happen. The scripts that you write will control the objects on your page.

Look at Listing 1.1. What tag in that listing do you think is most important? If you do a lot of writing, you might say that the Heading 1 <H1> tag is most important. If you're new to HTML and you're not sure how it works, you might think that the <HTML> tag is most important. If you consider what HTML offers, you'll realize that the most important tag in the listing is the <A HREF="... tag. This tag allows your document to be linked to any other document on the Web. This is important, because before HTML there was no standard way of linking two different document files on the Internet.

HTML is a standard that is maintained by the World Wide Web Consortium (W3C). W3C is a group of individuals and companies that develop and approve standards for the Web. HTML isn't the only standard maintained by W3C. Transport protocols, graphics formats for the Web, objects for the Web, and of course the implementation of scripting languages such as VBScript are also maintained by W3C.

Before you begin writing in Visual Basic Script, you need a little expertise in HTML. Let's review the basics now. For more detailed information, you can check out the reference information and links on the CD.

The <HTML> Tag

The way most HTML is written is with tags. Most of the time you will use two tags, placing your content between them.

The base tag for an HTML document is the <HTML> tag. All tags are enclosed by the less than (<) and greater than (>) characters. Closing tags are usually the same as opening tags except that they're preceded by a slash:

<HTML></HTML>

This line produces a legal HTML document. Of course, there is nothing to see in the document. The point is that the tags don't show up in the document; only the formatted text does.

The <HEAD> Tag

The <HEAD> tag sets initial document information off from the rest of the document. That information can include <TITLE>, <META NAME>, and other document administration tags.

The <TITLE> Tag

The <TITLE> tag tells the browser what you've named your page. The title of the page usually shows up in the title bar of the browser with which you're viewing the page. The <TITLE> tag is part of the <HEAD> tag in the HTML page.

The <BODY> Tag

The <BODY> </BODY> tags hold the content of your HTML document. Text that is between these tags is formatted to the browser's default style. Listing 1.2 shows a document that contains a line of body text. The style of text in the body of a document is determined by the tags that surround the text.

Listing 1.2. HTML page with a title and body text.

<HTML>

<HEAD>

<TITLE>Document Titles</TITLE>

</HEAD>

<BODY>

This is a titled document.

</BODY>

</HTML>

Headings

Heading levels in HTML documents range from <H1> to <H6>. In most browsers, the size and weight of heading text is largest at <H1> and smallest at <H6>. (See Figure 1.2.) Listing 1.3 shows you how the heading levels are set in the HTML document.

Figure 1.2 : Heading levels in an HTML document.

Listing 1.3. Headings in an HTML document.

<HTML>

<HEAD>

<TITLE>Heading Levels in an HTML Document</TITLE>

</HEAD>

<BODY>

<H1>Heading 1</H1>

<H2>Heading 2</H2>

<H3>Heading 3</H3>

<H4>Heading 4</H4>

<H5>Heading 5</H5>

<H6>Heading 6</H6>

</BODY>

</HTML>

TIP

Don't use heading tags to change the size of text on the page. There are other, more appropriate tags for that task. Use the heading tags as needed, in documents where an outline makes sense.

Heading tags are handy for setting off heading levels in an HTML page. Keep in mind, though, that what someone viewing your document sees can be completely different from what you see when you review your pages in your own browser.

Paragraphs

Paragraphs are the default groupings of text in an HTML page. The paragraph tag, <P>, can be used with or without a closing tag. Like the heading tags, the <P> tag can be used to create a break, but so can the break (<BR>) tag. It's up to you to choose the tags for your own pages, but as with the heading tag, logic should override aesthetics. The paragraph tag should be used to separate groups of text. If you're creating a break just so that the next item is on the following line, you should probably use the break tag.

The <FONT> Tag

The <FONT> tag is used with attributes to set the properties for text inside the tags. Let's go over some of the properties that you can easily change inside the font tags.

Size

The SIZE= attribute is similar to the heading tag. The size of the text inside the tags is set in the same manner. The difference is that the size tag is a formatting tool, as opposed to an organizational tool. It sets the size of text from 0 (smallest) to 7 (largest):

This is a <FONT SIZE=6>Large</FONT> example. This is a <FONT SIZE=1>small</FONT> one.

Face

The FACE= attribute allows you to set the font that is displayed in your reader's browser. For this tag to work, the font that's called must be installed on the client machine. Several different fonts can be specified. If one of the specified fonts is not installed on the client machine, the default font is used:

<FONT FACE="Arial, Sans">This text is displayed in Arial or Sans Serif if

these fonts are installed.</FONT>

Color

The COLOR= attribute allows you to set the color of text inside the font tags. There are two ways to set the color of a particular font. First, you can use the RGB value of a color, converted to hexidecimal:

<FONT COLOR=#FFFFFF>

You can also set the color of text by using color names. (See Table 1.1.) By using these names, you can be sure that colors are the same across machines.

Table 1.1. Color names in Explorer 3.0.