⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch28.htm

📁 CGI programming is the hottest stuff to look out for in this book
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<HR>
<P>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><B>Tip</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
If you're a Visual Basic programmer, you probably noticed that the <TT><FONT FACE="Courier">Dim</FONT></TT> statement doesn't say what the variable's type is in Listing 28.2; it doesn't need to. In VBScript, everything is considered a data variant and is 
classified by what gets tossed inside it later on.
</BLOCKQUOTE>

</TD></TR>
</TABLE></CENTER>
<P>
<P>
Two concepts in the script shown in Listing 28.2 serve as the
basis for almost all interactions: referencing by name and referencing
by action. <I>Referencing by name</I> means that any item you
want to use with something else, be it a CGI script or a VBScript
function, should be uniquely named so that other things can get
access to it later. When text is obtained for the message box,
it looks for the form named <TT><FONT FACE="Courier">MyForm</FONT></TT>,
then for the <TT><FONT FACE="Courier">namebox</FONT></TT> element
in that form, and finally for the <TT><FONT FACE="Courier">Value</FONT></TT>
of that element. You can easily have multiple forms on a page
and one big VBScript that handles all of them; you just have to
name everything carefully so that there's no confusion.
<P>
<I>Referencing by action</I> is more general because it uses the
name of an element and then an action that would normally be associated
with it. The most common is finding out when a particular button
is clicked, which is referenced as an <TT><FONT FACE="Courier">OnClick</FONT></TT>
event. <TT><FONT FACE="Courier">Sub SayHi_OnClick</FONT></TT>
uses both name and action to define when this particular subroutine
should be run, not just what its name is.
<P>
With good referencing, knowledge of the Object Model of the browser
or viewer comes into play. To get something done, you have to
know what the name of the function is (if it's available) and
how to organize your commands so that they get to the right element
and do the right thing. Remember that the Object Model can also
include reference for what kind of actions (methods) are supported.
You can create buttons that do the navigation for you or combo
boxes (like at Microsoft's site, though they don't use VBScript
for it yet).
<H4>What's Not in VBScript?</H4>
<P>
People who have been developing with Visual Basic for some time
may find that a lot of stuff is not in VBScript. Some elements
are missing for security reasons, others for keeping the runtime
engine small, and others, well, just because.
<P>
First and foremost, VBScript limits the functionality available
in the development environment. How much of it? Almost the whole
thing. Gone are such useful elements as the editor, the debugger,
the project manager, and source code controls. Welcome to your
new development environment: Notepad or your favorite text editor.
Will this change? Quite possibly. With FrontPage as a front end,
Microsoft may decide to turn it into an Integrated Development
Environment, providing the tools you need to create VBScript as
an add-on feature.
<P>
Second, VBScript can't create user interfaces-not a one-unless,
of course, you believe that a message box is a good user interface,
in which case you can rejoice. You can, however, take control
of HTML elements such as listboxes, checkboxes, and other elements
mentioned previously to get the components you need.
<P>
Last, but certainly not least to VB developers, is that the controls
and commands in VBScript are a subset of Visual Basic for Applications
(VBA), which is itself a subset of Visual Basic. Translated, this
means that a lot of elements were left out to make VBScript tiny
and efficient. If you're an experienced Visual Basic programmer,
you may want to look in the &quot;Resources&quot; section to see
just what some of these elements are so that you can determine
what you have available in your toolbox. If you're not a Visual
Basic programmer with prior experience, you can just stick with
the VBScript documentation, which will keep you from fretting
about what might have been there and ground you on what's actually
there that you can use.
<H2><A NAME="ScriptingHostsandEngines"><FONT SIZE=5 COLOR=#FF0000>Scripting
Hosts and Engines</FONT></A></H2>
<P>
Your ability to run an ActiveX script, regardless of its language,
is based on two elements:
<OL>
<LI>A host browser or viewer that supports ActiveX
<LI>An ActiveX control, or engine, for the script language
</OL>
<P>
Although getting one or the other may be easy, without your hard
work and these two elements, your script doesn't do anything once
it gets where it's going.
<H3><A NAME="Hosts">Hosts</A></H3>
<P>
Although most browsers and viewers easily handle HTML, trying
to convince them to deal with a new scripting language can be
difficult. Fortunately, any host that allows ActiveX controls
to hang on to it is a lot more flexible.
<H4>Internet Explorer</H4>
<P>
Internet Explorer, as I said earlier, is really just a big container
with lots of components added on to make it work. The main executable
that starts it all is well under 50K (less than half that, in
the early stages of beta), and the majority of the work is done
by other DLLs and OCXs, such as MSHTML.DLL (which is several hundred
kilobytes, and does almost all the HTML work). The rest of the
ActiveX strategy uses this same approach-build in little pieces
and add on when you need them. Using this approach keeps containers
small and updateable, while still being transparently expandable.
<P>
Because it is from Microsoft and able to handle all sorts of ActiveX
expansions, Internet Explorer is capable of supporting ActiveX
scripting implementations both now and in the future.
<H4>Future Hosts</H4>
<P>
Microsoft is working on removing the distinction between files
on the Internet and files on the desktop. As other shells become
available with built-in HTML and URL support, chances are built-in
script controls will be implemented as well. More value would
be added by supporting the scripting information in more hosts
as well, such as server-based scripting and other Internet-related
authoring tools (just as Visual Basic for Applications is supported
in large applications, adding the lighter VBScript version to
small applications would be a possibility). All you really need
is an engine to attach to the viewer.
<P>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><B>Note</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
Many developers may be wondering, &quot;But what about Netscape? Don't they support ActiveX scripting?&quot; In the early ActiveX stages, Netscape announced that it had no plans to support ActiveX, and that would mean scripting as well. Some good news 
appeared for developers, however, when Ncompass labs of Vancouver started developing ActiveX intermediaries for Netscape as plug-ins. The ScriptActive plug-in is the first step toward enabling ActiveX scripting on a Netscape Navigator client. Only time 
will tell if Netscape changes the decision not to support ActiveX natively, however.</BLOCKQUOTE>

</TD></TR>
</TABLE></CENTER>
<P>
<H3><A NAME="Engines">Engines</A></H3>
<P>
To add support for another scripting language, such as Perl, Tcl/Tk,
or Joe Bob's Miracle Script, all you need is another ActiveX control
container that the viewer can use. Because you can set up ActiveX
controls to download automatically, you don't really need to worry
about forcing people to get this container. Make it available
where the scripts are, and it can take care of that obnoxious
task all by itself. (See &quot;Internet Component Download,&quot;
in <A HREF="ch27.htm" >Chapter 27</A>, &quot;ActiveX Controls.&quot;)
<P>
Creating such a container can be a daunting task. You need intimate
knowledge of the language in question and the ability to test
every situation that could be encountered, all the functions,
and even all the hosts it could be used on. The most likely candidates
for their own engines would be popular scripting languages such
as Perl and Tcl, because large numbers of programmers who use
these languages have the resources to do these kinds of tasks.
For a one-person shop or even a two- or three-person shop, creating
such an engine would be a Herculean task-but impressive!
<H2><A NAME="Resources"><FONT SIZE=5 COLOR=#FF0000>Resources</FONT></A>
</H2>
<P>
In the pursuit of VBScript excellence, you'll make a lot of stops
along the way, as you learn in the following sections.
<H3><A NAME="GoingfromVBtoVBScript">Going from VB to VBScript</A>
</H3>
<P>
If you're already a Visual Basic programmer, you may want to look
for utilities that convert your existing VB applications to VBScript
and HTML or ones that can at least use your original VB code to
create a starting point. The biggest benefit may not be full conversion,
but you may gain an educational tool to let you see how what you
do in VB may or may not be transportable. Even if a utility turns
out a horrible overall conversion, but has a small portion that
works, you can put that component to work and build from there.
<P>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 width=80%>
<TR><TD><B>Tip</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
Although a number of these tools were in development at the time of writing, none were in a state where they could be reliably tested or recommended. Check the Microsoft Web site and your favorite search engines for the keywords &quot;VBScript 
converter,&quot; and you should get a number of matches which may be of use.</BLOCKQUOTE>

</TD></TR>
</TABLE></CENTER>
<P>
<H3><A NAME="VBScriptLanguageandRuntimeReferences">VBScript Language
and Runtime References</A></H3>
<P>
Tables 28.1 through 28.4 show what functions are supported in
the first iteration of VBScript and what's not. For these tables,
I'm assuming that you're either familiar enough with Visual Basic
to make some sense out of what you see listed or that you'll be
willing to track down a comprehensive reference on Visual Basic
and find the meanings there.<BR>
<P>
<CENTER><B>Table 28.1. VBScript language reference.</B></CENTER WIDTH=80%>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1>
<TR><TD><CENTER><I>Type of Function </I></CENTER></TD>
<TD WIDTH=396><CENTER><I>Available Feature(s)</I></CENTER></TD>
</TR>
<TR><TD WIDTH=194>Arrays</TD><TD WIDTH=396>Declaration (<TT><FONT FACE="Courier">Dim</FONT></TT>, <TT><FONT FACE="Courier">Static</FONT></TT>, and so on),<TT><FONT FACE="Courier"> LBound</FONT></TT>, <TT><FONT FACE="Courier">UBound</FONT></TT>, <TT><FONT 
FACE="Courier">ReDim</FONT></TT>, <TT><FONT FACE="Courier">Erase</FONT></TT>
</TD></TR>
<TR><TD WIDTH=194>Assignment</TD><TD WIDTH=396><TT><FONT FACE="Courier">=</FONT></TT>, <TT><FONT FACE="Courier">Let</FONT></TT>, <TT><FONT FACE="Courier">Set</FONT></TT>
</TD></TR>
<TR><TD WIDTH=194>Comments</TD><TD WIDTH=396><TT><FONT FACE="Courier">REM</FONT></TT> and <TT><FONT FACE="Courier">'</FONT></TT>
</TD></TR>
<TR><TD WIDTH=194>Control flow</TD><TD WIDTH=396><TT><FONT FACE="Courier">Do...Loop</FONT></TT>, <TT><FONT FACE="Courier">For...Next</FONT></TT>, <TT><FONT FACE="Courier">For Each...Next</FONT></TT>, <TT><FONT FACE="Courier">While...Wend</FONT></TT>, 
<TT><FONT FACE="Courier">If... Then...Else</FONT></TT>
</TD></TR>
<TR><TD WIDTH=194>Error trapping</TD><TD WIDTH=396><TT><FONT FACE="Courier">On Error</FONT></TT>, <TT><FONT FACE="Courier">Resume</FONT></TT>, <TT><FONT FACE="Courier">NextErr</FONT></TT> object
</TD></TR>
<TR><TD WIDTH=194>Literals</TD><TD WIDTH=396><TT><FONT FACE="Courier">Empty</FONT></TT>, <TT><FONT FACE="Courier">Nothing</FONT></TT>, <TT><FONT FACE="Courier">Null</FONT></TT>, <TT><FONT FACE="Courier">True</FONT></TT>, <TT><FONT 
FACE="Courier">False</FONT></TT>, User-defined literals: <TT><FONT FACE="Courier">123.456</FONT></TT>, <TT><FONT FACE="Courier">Foo</FONT></TT>, and so on
</TD></TR>
<TR><TD WIDTH=194>Miscellaneous</TD><TD WIDTH=396>Line continuation character (_), line separation character (<TT><FONT FACE="Courier">:</FONT></TT>)
</TD></TR>
<TR><TD WIDTH=194>Nonconforming identifiers</TD><TD WIDTH=396><TT><FONT FACE="Courier">o.[<I>My long method name</I>]</FONT></TT>
</TD></TR>
<TR><TD WIDTH=194>Operators</TD><TD WIDTH=396>Arithmetic: <TT><FONT FACE="Courier">+</FONT></TT>, <TT><FONT FACE="Courier">-</FONT></TT>, <TT><FONT FACE="Courier">*</FONT></TT>, <TT><FONT FACE="Courier">/</FONT></TT>, <TT><FONT 
FACE="Courier">\</FONT></TT>, <TT><FONT FACE="Courier">^</FONT></TT>,
</TD></TR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -