Tải bản đầy đủ (.pdf) (774 trang)

VBScript UNLEASHED ebook

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.25 MB, 774 trang )

CONTENTS
VBScript

UNLEASHED
Petroutsos, Schongar, et al.
CONTENTS
Chapter 1
Introducing HTML Scripting
● 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
:8080/VB/ (1 of 18) [16/Oct/2002 2:33:11 PM]


CONTENTS
Chapter 2 The VBScript Language
● Introduction
● Differences Between Visual Basic and VBScript
● Programming in VBScript
❍ Creating a Test Page
❍ What a Program Is
❍ Concepts You Should Understand: Variables and Procedures
❍ The Anatomy of VBScript Code
● Data Types
❍ Subtypes of Variant Types
❍ Using Variables
❍ Constants
● Program Flow
❍ Operators
❍ Decision-Making in Programs
❍ If Then Else
❍ For Next
❍ Do Loop
❍ For Each Next
❍ While Wend
● Review
Chapter 3 VBScript Functions
● Introduction
● Procedures in Scripts
❍ Sub Procedures and Function Procedures
❍ Arguments to Procedures
❍ Creating and Calling Functions
● Intrinsic Functions
● Basic Functions

❍ InputBox
❍ len
❍ MsgBox
❍ VarType
● String Functions
:8080/VB/ (2 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
❍ Asc
❍ Chr
❍ InStr
❍ LCase
❍ Left
❍ LTrim
❍ Mid
❍ Right
❍ RTrim
❍ Str()
❍ StrComp
❍ String
❍ Trim
❍ UCase
❍ Val
● Conversion Functions
❍ CByte
❍ CDbl
❍ CInt
❍ CLng
❍ CStr
❍ CVErr
● Math Functions

❍ Abs
❍ Array
❍ Atn
❍ Exp
❍ Hex
❍ Int
❍ Fix
❍ Log
❍ Oct
❍ Rnd
❍ Sgn
❍ Sqr
❍ Sin
❍ Tan
● Time and Date Functions
❍ Date
:8080/VB/ (3 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
❍ DateSerial
❍ DateValue
❍ Day
❍ Hour
❍ Year
❍ Weekday
❍ Minute
❍ Month
❍ Now
❍ Second
❍ Time
❍ TimeSerial

❍ TimeValue
● Boolean Functions
● Review
Chapter 4 Intrinsic Controls
● Introduction
● Events in VBScript
● Messages in a GUI Environment
● Placing Controls in HTML
● Intrinsic Controls
❍ Button
● Checkbox
❍ Hidden
❍ Text
❍ Textarea
● Select
● Using Controls in Your Documents
● Review
Chapter 5 VBScript in Web Pages
● Using VBScript and HTML
❍ Using the onLoad Event
❍ Embedding VBScript in the HTML
:8080/VB/ (4 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
❍ Creating a New Page with VBScript
● Using VBScript and CGI/ISAPI
● Providing Database Access
❍ Defining an ODBC Datasource
❍ Creating the IDC Script File
❍ Creating the Output Template File
❍ Viewing the Results

● Review
Chapter 6 The Scripting Model
● Windows, Documents, and Frames
❍ The window Object's Properties
❍ Methods
● The document Object
❍ The document Object's Properties
❍ The document Object's Methods
● Using the document Properties and Methods
❍ A Self-Modifying Document
❍ Color Cycling
❍ A Yearly Calendar
● The history Object
❍ The HistoryObject Project
● The navigator Object
❍ The BrowserInfo Project
❍ The NavigatorObject Project
● The location Object
❍ The LocationObject Project
● The link Object
❍ The LinksObject Project
● Review
Chapter 7 Using ActiveX Controls
● Looking at a Brief History of Custom Controls
● Examining the Anatomy of an ActiveX Control
● Registering Your ActiveX Controls
:8080/VB/ (5 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
● Putting an ActiveX Control in Your Web Page
● Installing and Distributing ActiveX Controls

● Examining ActiveX Controls
❍ Animated Button Control
❍ Chart Control
❍ Label
❍ Popup Menu Control
❍ Preloader Control
❍ StockTicker Control
❍ Timer Control
● Using Third-Party Controls
● Using Signed Controls
● Creating ActiveX Controls
❍ Using the Control Wizard to Create the Skeleton Files
❍ Compiling a Control
❍ Registering Your Control
❍ Testing Your Control
● Creating Non-MFC ActiveX Controls
● Signing Your Objects for Internet Use
● Review
Chapter 8 The ActiveX Control Pad
● Taking a Tour of the ActiveX Control Pad
❍ Text Editor
❍ Object Editor
❍ Page Editor
❍ Script Wizard
● Using ActiveX Controls
● Creating VBScript with the Script Wizard
● Using HTML Layouts
● Looking at the Available Controls
● Adding Controls to the Toolbox
● Creating Interactive Content

● Using VBScript with ActiveX Layouts
● Review
:8080/VB/ (6 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
Chapter 9 More ActiveX Controls
● The Popup Menu and Menu Controls
❍ The Popup Menu
❍ The Menu Control
❍ The Popup Window Control
❍ The Marquee Control
❍ The Chart Control
❍ The Chart Example
● Review
Chapter 10 Error Handling
● Handling Errors in Your VBScript Pages
❍ Syntax Errors
❍ Errors with ActiveX Controls
❍ Runtime Errors
● Coding to Avoid Errors
❍ Using the ActiveX Control Pad
❍ Using Option Explicit
❍ Using Coding Conventions
● Coding to Handle Errors
❍ Specifying Error Trapping
❍ Using the Err Object
● Looking at Examples of Error Handling
❍ Trapping Runtime Errors
❍ Using the Raise Method
● Review
Chapter 11 Optimizing Code

● Organizing Your Code
❍ Chaos Theory 101
❍ Code Behind the Scenes
● Error Checking and Debugging
● Use of Functions and Syntax
❍ Variables Versus References
:8080/VB/ (7 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
❍ Data Types
● ActiveX Controls
❍ Quality, Not Quantity
❍ Divide and Conquer
● Development Tools
❍ Still Using a Text Editor?
❍ ActiveX Control Pad
❍ Visual Basic to VBScript Converters
❍ Future Integrated Development Environments?
● Review
Chapter 12 Debugging
● Handling VBScript Errors
❍ Syntax Errors: Say What You Mean!
❍ Semantic Errors: Mean What You Say!
● Using Simple Debugging Techniques
❍ Using the MsgBox Statement
❍ Using the On Error Resume Next Statement
❍ Using the Err Object
❍ Taking the Err Object Further
● Using Advanced Debugging Techniques
❍ Tracing Your Code Using the Message Box
❍ Saturating Your Code with the Message Box

❍ Watching Your Code Using Variables and the Message Box
❍ Breaking Apart Complex Statements to Find Bugs
● Using Other Tools to Help You with the Debugging Task
● Using VBScript Versus Traditional Debugging Environments
● Using Visual Basic to Debug VBScript Applications
❍ Using Visual Basic 4.0 Trace Capabilities
❍ Debugging VBScript Code Within Visual Basic
● Handling HTML Errors
● Making Sure the Bugs Are Dead
● Creating Your Own Debug Window for Tracing
● Building Your Own Tracing Routines
● Looking at a Sample Variable Analysis Routine
● Looking at More Reasons Why VBScript Can Be Tough to Debug
● The Moral of the Story
:8080/VB/ (8 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
● Review
Chapter 13 Dynamic Web Page Building
● Using the Internet Explorer Document Object
❍ Properties and Collections
❍ Methods
● Using the ActiveX Timer Control
● Writing the Current Date and Time to the Page
● Creating a Random Frame Using Client-Side Refresh
● Changing the Document's Colors
● Using Cookies to Maintain User Information
● Review
Chapter 14 Customize Your Web Page with
Cookies
● Safety Considerations

● What Are Cookies?
❍ Creating Cookies
❍ How to Test Pages with Cookies
● The Cookie Folder
● Extracting the Cookie Values
● Review
Chapter 15 Creating Active Documents for
Corporate Intranets
● Client-Side Processing
● Distributed Applications
❍ Databases
● Functionality and Flexibility
❍ Native Document Hosting
❍ Component Architecture
❍ Third-Party Innovation
:8080/VB/ (9 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
● Return on Investment (ROI)
❍ Maintenance
❍ Expansibility and Integration
❍ Standards
❍ Investment Protection
❍ Employee Efficiency
❍ Company Image
● Review
Chapter 16 Controlling MS Office Documents in
Web Pages
● ActiveX
● ActiveX Scripting
● ActiveX Control Pad

● Leveraging Your Investment
● Microsoft Office Suite
● Relevant Web Sites
● Review
Chapter 17 Animation
● ActiveX Controls Capable of Animation
● Frame Animation with Image and Timer Controls
● Rotating Text with the Label Control
● Using Active Movie for Digital Audio and Video
● The Marquee Control for Scrolling Pages
● Other HTML Tags that Provide Multimedia Playback
Chapter 18 VBScript and Java
● What Is Java?
● Java, Java Applets, and JavaScript
● Java Classes
● JavaScript Objects
● JavaScript Language Structure
:8080/VB/ (10 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
❍ JavaScript Operators
❍ JavaScript Flow of Control Statements
● VBScript Language Structure
❍ VBScript Examples
❍ VBScript Variables
❍ VBScript Operators
❍ VBScript Err Object
❍ VBScript Variant Data Type
❍ VBScript Constants
❍ VBScript Flow of Control Statements
❍ VBScript Functions

❍ VBScript Procedures
❍ ActiveX
● Standards and Conventions
● Comparing Java, JavaScript, and VBScript: A Summary
● Examples
● Relevant Web Sites
● Review
Chapter 19 VBScript and DLLs
● Static Versus Dynamic Library
● Structure of a DLL
❍ The Entry Function
❍ The LibMain Function
❍ The Exit Function
● Programmer-Defined Functions
❍ Exported Functions
❍ Non-Exported (Internal) Functions
● Why Use DLLs?
● Disadvantages of Using DLLs
● A Sample DLL
● VBScript and DLLs
● Relevant Web Sites
● Review
Chapter 20 CGI and VBScript
:8080/VB/ (11 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
● Understanding CGI
● CGI Specification
● CGI Environment Variables
● Architecture of a CGI Application
● CGI Versus VBScript

● Examples
● Relevant Web Sites
● Review
Chapter 21 Safety and Security
● A Matter of Trust…
❍ Can VBScript Security Hold Up?
● VBScript's Built-In Safeguards
● Flirting with Danger-ActiveX Components
❍ Authentic Controls-Friend or Foe?
❍ Rogue Controls
❍ Defending Against Friendly Fire and Nasties
● Paranoia, Self-Defense, and Reasonable Risk
Chapter 22 VBScript as a Component in Other
Applications
● Porting VBScript to VBA and Visual Basic
● All About ActiveX Scripting
❍ Script Engines
❍ Script Hosts
❍ Communications Between Scripting Engines and Hosts
● Licensing
❍ The Binary Route
❍ Source Code
● Putting It All Together-Microsoft's "Spruuids" Example
● Future Hosts
Chapter 23 Conversions and Calculations
:8080/VB/ (12 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
● Metric Conversions
❍ The User Interface
❍ The TabStrip Control

❍ Implementing the Conversions Utility
❍ Programming the Application
● A Financial Calculator
❍ The User Interface
● A Math Calculator
❍ The User Interface
❍ Programming the Application
❍ Improving the Calculator
❍ Further Improvements
● Review
Chapter 24 WWW Personal Information Manager
● Overview
● How It Works
● Creating the Page
❍ Working with Cookies
❍ Creating Dynamic HTML
❍ Presenting Information
❍ Tying It All Together
● Review
Chapter 25 Order Entry
● Ensuring Secure Transactions on the Web
❍ Authenticating the Merchant
❍ Authenticating the Purchaser
❍ Encrypting Web Communications
● Reviewing Cookies
● Designing the Order Entry Form
● Creating the Order Entry Form
● Examining the VBScript Code
● Testing the Application
● Review

:8080/VB/ (13 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
Chapter 26 RTFEditor
● Using OCX Controls with VBScript
❍ The RTFEditor Application
❍ The Rich Textbox Control
❍ Designing the User Interface
❍ The Code Behind the Scenes
❍ 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
:8080/VB/ (14 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
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 :

e-mail :

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
Services:

Cindy Morrow Assistant Marketing
Managers:
Kristina Perry, Rachel
Wolfe
Acquisitions Editor Christopher Denny Development Editor Anthony Amico
Software Development
Specialist
Brad Myers Production Editor Mary Inderstrodt
Copy Editors Heather Butler, Keith
Davenport, Karen
Letourneau
Indexer Johnna VanHoose
Technical Reviewer Greg Guntle Editorial Coordinator Katie Wise
:8080/VB/ (15 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
Technical Edit
Coordinator
Lynette Quinn Resource Coordinator Deborah Frisby
Editorial Assistants Carol Ackerman, Andi Richter, Rhonda Tinch-Mize
Cover Designer Gary Adair Book Designer Gary Adair
Copy Writer Peter Fuller Production Team
Supervisor
Brad Chinn
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 (
and ). 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

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.
:8080/VB/ (16 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS
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


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
.
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:

Mail: Greg Wiegand
Sams.net Publishing
201 W. 103rd Street
Indianapolis, IN 46290
:8080/VB/ (17 of 18) [16/Oct/2002 2:33:11 PM]
CONTENTS


:8080/VB/ (18 of 18) [16/Oct/2002 2:33:11 PM]
Chapter 1 Introducing HTML Scripting
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
:8080/VB/ch1.htm (1 of 24) [16/Oct/2002 2:33:34 PM]
Chapter 1 Introducing HTML Scripting
● 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, :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
:8080/VB/ch1.htm (2 of 24) [16/Oct/2002 2:33:34 PM]
Chapter 1 Introducing HTML Scripting
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
:8080/VB/ch1.htm (3 of 24) [16/Oct/2002 2:33:34 PM]
Chapter 1 Introducing HTML Scripting
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>
:8080/VB/ch1.htm (4 of 24) [16/Oct/2002 2:33:34 PM]
Chapter 1 Introducing HTML Scripting
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
:8080/VB/ch1.htm (5 of 24) [16/Oct/2002 2:33:34 PM]
Chapter 1 Introducing HTML Scripting
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.
Black White Green Maroon
Olive Navy Purple Gray
Red Yellow Blue Teal
Lime Aqua Fuchsia Silver
:8080/VB/ch1.htm (6 of 24) [16/Oct/2002 2:33:34 PM]
Chapter 1 Introducing HTML Scripting
These color names can also be used with other tags, including the BODY, HR, MARQUEE, and TABLES tags. If you view Listing
1.4 in your browser, you can get a look at these colors. (See Figure 1.3.)
Figure 1.3 : Colorname values in Internet Explorer 3.0.
Listing 1.4. Colornames.htm.
<HTML>
<HEAD>
<TITLE>Colornames in Explorer 3.0</TITLE>
</HEAD>
<BODY>
<FONT SIZE=6>These are the colornames available to you using the COLOR tag.</FONT>
<P>
<FONT COLOR="BLACK">BLACK</FONT><FONT COLOR="WHITE">WHITE</FONT>

<FONT COLOR="GREEN">GREEN</FONT><FONT COLOR="MAROON">MAROON</FONT>
<P>
<FONT COLOR="OLIVE">OLIVE</FONT><FONT COLOR="NAVY">NAVY</FONT>
<FONT COLOR="PURPLE">PURPLE</FONT><FONT COLOR="GRAY">GRAY</FONT>
<P>
<FONT COLOR="RED">RED</FONT><FONT COLOR="YELLOW">YELLOW</FONT>
<FONT COLOR="BLUE">BLUE</FONT><FONT COLOR="TEAL">TEAL</FONT>
<P>
<FONT COLOR="LIME">LIME</FONT><FONT COLOR="AQUA">AQUA</FONT>
<FONT COLOR="FUCHSIA">FUCHSIA</FONT><FONT COLOR="SILVER">SILVER</FONT>
</BODY>
</HTML>
Links in Your Documents
:8080/VB/ch1.htm (7 of 24) [16/Oct/2002 2:33:34 PM]

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×