Student Menu. © Lesson 2. Printable layout. Links won't function in print.

Notes Section

Main Text

 

Module 2.0

 

 

 

 

 

 

 

 

 

 

 

 

*As JavaScript and JScript reach full compliance with ECMAScript Standards, their inconsistencies in Netscape and IE browsers will diminish and a vendor-neutral, client-side scripting language will hopefully emerge on the Web.

 

 

The European Computer Manufacturers Association’s (ECMA) goal is to foster a reliable scripting standard. Both Netscape and Microsoft have pledged future version compliance.

 

What are VBScript, JScript and JavaScript?


All are interpreted scripting languages requiring an interpreter and are capable of running on a web browser like Netscape’s Navigator or Communicator and Microsoft’s Internet Explorer (IE).

 

VBScript: Based on the Visual Basic (VB) programming  language. Both VBScript and Visual Basic for Applications (VBA) are subsets of the VB language. VBScript is an embeddable language requiring a scripting host and cannot be compiled into an independent application.

 

JScript: Introduced by Microsoft to compete against Netscape’s popular JavaScript. Both JavaScript 1.1 and JScript 2.0 were the source for ECMAScript*, the only standardized Web scripting language.

 

JavaScript: The first client-side scripting language. Originally called LiveScript. Strategically renamed under agreement with Sun Microsystems to take advantage of the Java marketing publicity. JavaScript and Java are distinctly different languages: JavaScript is interpreted while Java is compiled (into bytecode).

 

 

Advantage

Disadvantage

VBScript

Easiest to learn. Internet Explorer (IE) supported.

Netscape requires plug-in: www.ncompasslabs.com

JScript

Reverse engineering of JavaScript by Microsoft.

Rarely used. Not directly* supported by Netscape.

JavaScript

The only browser independent client-side scripting language. JavaScript interpreters are in both IE (JavaScript 1.1, as ECMAScript) and Netscape (JavaScript 1.2). Capable of server-side scripting including for use in creating ASP pages.

 

 

Module 2.1

 

 

 

The <SCRIPT> tag with the language attribute <SCRIPT LANGUAGE = VBSCRIPT> encloses client-side scripts.

 

 

By adding <SCRIPT RUNAT=SERVER> a script may be forced to run at the server rather than the client.

 

 

Order of execution:

1.        global.asa*

2.        include files*

3.        HTML and <%  %>

4.        <SCRIPT>**

5.        <SCRIPT RUNAT= SERVER>***

 

 

*global.asa will be covered in ASP Part II and include files will be mentioned shortly.

 

 

**The <SCRIPT> tags are client-side and executed in order of appearance in the ASP application. At the very top, they’ll execute first. At the very bottom, they’ll execute just before the server-side code within the <SCRIPT RUNAT = SERVER> tags.

 

 

***Code within the <SCRIPT RUNAT = SERVER>  tags are the very last to be executed even if appearing at the very top of an ASP application.

 

 

What is the Difference Between Client-Side and Server-Side Scripting?

 

1. The client is the web browser; the server is the web server. VBScript, JScript and JavaScript are all capable of running on the server or the browser depending on coding syntax.

 

2. Mathematics has an order of operations. First multiplication or division (from left to right), then addition or subtraction (also from left to right). Therefore, the answer to this equation,  24 / 6 + 2 * 6 - 2,  is 14. Twenty-four divided by six is four. Two multiplied by six is twelve. Four added to twelve is sixteen. Sixteen subtracted by two is fourteen. Copy and paste the equation into WebMath. See the hints section if you have trouble.

 

3. Web browsers have an order of execution. The global.asa and include files are first and second, respectively*. HTML and code inside the ASP script delimiters <%  %> are third. The <SCRIPT> tags are executed in order of appearance** in the ASP application but always before the <SCRIPT RUNAT=SERVER> enclosed code which is executed very last***.

 

4. Open the Part1 folder in Windows Explorer > right click > New > Text Document > name it OrderEx2.asp > Yes (make certain the file has the .asp extension rather than the .txt extension). Copy and paste the following text into OrderEx2.asp:

 

<HTML><HEAD><TITLE>OrderEx2</TITLE></HEAD><BODY>

January, <%= "<U>February</U>," %> March,

   <SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>

   Response.Write "<I>April</I>,"

   </SCRIPT>

May, June, <%= "<U>July</U>," %> August,

   <SCRIPT LANGUAGE=JAVASCRIPT>

   document.write ("<B>September</B>,");

   </SCRIPT>

October, <%= "<U>November</U>," %> December.

</BODY></HTML>

 

You will see the following output:

 

January, February, March, May, June, July, August, September, October, November, December. April,

 

Although written in correct order in the application above, the months show an incorrect sequence after execution. First HTML (plain text) and <%  %> (underlined text), then <SCRIPT> (bold text) and finally <SCRIPT RUNAT=SERVER> (italic text). 

 

 

Module 2.2

 

 

What are Data Types, Variables, Constants, Operators and Arrays in VBScript? (review only)

 

1. In VBSLR click the Search tab > type Data Types > click List Topics > double-click the first choice VBScript Data Types > click the Refresh button to remove the highlighting.

 

2. Use the Next link in the upper right-hand corner and critically review Variables, Constants and Operators. It is highly recommended that you paraphrase or outline this very important information in order to understand it better. The sooner you master these concepts, the easier it becomes to develop ASP applications.

 

3. Arrays are more effective than variables for storing a series of related data items. Each data item in the series is referenced by an index number which begins at zero. Arrays are declared like variables using the Dim keyword, and they may be fixed or dynamic. As the last exercise will demonstrate, the power of an array is in its ability to manipulate a series of data items as if they were a single data item.

It is highly recommended that you paraphrase or outline this very important information in order to understand it better. The sooner you master these concepts, the easier it becomes to write your own ASP applications. See these topics in the VBSLR.

 

 

Module 2.3

 

What Are Control Statements in VBScript? (review only)

 

1. Some control statements branch: If-Then and  Select-Case.

 

2. Other control statements loop: For-Next, For-Each, While-Wend, Do-Until, Do-While and the Exit Statement.

 

3. Still other control statements jump: Functions and Sub Procedures.

 

4. A miscellaneous control statement is the With Statement.

 

In VBSLR click the Index tab > type Control > double-click the first choice, controlling flow > a window will appear with several topics to critically review. Do the same for the words Array Variable, Function, Sub Procdure, Exit and With. Try to modify the Vbscript code examples at the bottom of each topic and test them out in your browser.

 

It is highly recommended that you paraphrase or outline this very important information in order to understand it better. The sooner you master these concepts, the easier it becomes to write your own ASP applications. See these topics in the VBSLR.

 

 

Module 2.4

 

Commenting Code and Include Files.

 

Commenting Code.

 

It cannot be understated the importance of thoroughly commenting code or hypertext mark-up. Intellectual property like code or mark-up becomes useless without comments just like a book report is worthless without a bibliography. Headaches are created for people who weren’t the original developers of the application if there isn’t a clear step-by-step description of what the application does and how the application does it. All formally trained programming professionals thoroughly comment their code and mark-up!

 

1.      HTML: <!-- This is an HTML comment. -->

 

2.      VBScript: This is a VBScript comment.

In VBSLR > select the Index tab > type formatting > double click formatting code > see the bottom. The apostrophe creates VBScript comments.

 

3.      ASP: <% ’ This is a one-line ASP comment. %>

Paragraphs of comments may be created in ASP as shown below.

<%

-----------------------------------------------------------------------------

                                 *** DESCRIPTION ***

  The method to comment code in ASP is just like VBScript.

  Use the apostrophe inside the script delimiters, <% %>.

-----------------------------------------------------------------------------

%>

 

Include Files.

 

Include files facilitate site management and code reusability. They may have an .inc, .asp, .txt or .htm extension and a physical or virtual path. Exercise 2 will demonstrate the effortlessness of include files.

 

Module 2.5

 

 

Exercise 2.

 

Open the Part1 folder in Windows Explorer > right click > New > Text Document > name it ArrayForNextIncEx2.asp > Yes (make certain the file has the .asp extension rather than the .txt extension). Copy and paste the following text into ArrayForNextIncEx2.asp:

 

<HTML><HEAD><TITLE>ArrayForNextIncEx2</TITLE></HEAD><BODY>

<!-- Add include file with a physical path -->

<!-- #include file="Menu.htm" -->

 

<%

'-----------------------------------------------------------

'This application demonstrates the use of Arrays, For-Next

'Loops, Comments and Include Files with physical and

'virtual paths.

'

'Created: 08/13/2000, By: Instructor, Revised: 08/13/2000

'-----------------------------------------------------------

 

Dim strLearningToCount()       'Dimension dynamic array.

Redim strLearningToCount(4)    'Declare five items.

strLearningToCount(0) = "One"  'Arrays begin at zero.

strLearningToCount(1) = "Two"

strLearningToCount(2) = "Three"

strLearningToCount(3) = "Four"

strLearningToCount(4) = "Five"

%>

 

<!-- Add HTML tags -->

<BR>I'm learning to count.<BR><BR>

 

<!-- Begin For-Next Loop) -->

<% For intCounter = 0 to 4 %>

<% =strLearningToCount(intCounter) %>,<BR>

<% Next %>

 

<!-- Add HTML tags -->

<BR> I can count higher than five! <BR><BR>

 

<%

Redim Preserve strLearningToCount(6) 'Re-dimension array.

strLearningToCount(5) = "Six"

strLearningToCount(6) = "Seven"

%>

 

<!-- Redim For-Next Loop) -->

<% For intCounter = 0 to 6 %>

<% =strLearningToCount(intCounter) %>,<BR>

<% Next %>

 

<!-- Add include file with a virtual path -->

<!-- #include virtual="Part1/FooterInfo.inc" -->

</BODY></HTML>

 

Save this as Menu.htm in the Part1 folder.

 

<div align="center"><center>

  <table border="2" cellpadding="0" cellspacing="0" width="100%" bordercolor="#FF0000">

    <tr>

      <td width="20%" align="center"><font color="#0000FF"><b>Link 1</b></font></td>

      <td width="20%" align="center"><font color="#0000FF"><b>Link 2</b></font></td>

      <td width="20%" align="center"><font color="#0000FF"><b>Link 3</b></font></td>

      <td width="20%" align="center"><font color="#0000FF"><b>Link 4</b></font></td>

      <td width="20%" align="center"><font color="#0000FF"><b>Link 5</b></font></td>

    </tr></table></center>

</div>

 

Save this as FooterInfo.inc. Don’t worry about the code.

 

<%

Dim strPathInfo, strPhysicalPath 'Declare two variables

 

'*******************************************************

'ASP OBJECTS ARE COVERED IN THE ASP PART 2 AND 3 CLASSES

'Don't worry if you don't understand what is going on.

'*******************************************************

 

'Assign variables to built-in ASP server object

'collection (ServerVariables) and method (MapPath)

strPathInfo = Request.ServerVariables ("PATH_INFO")

strPhysicalPath = Server.MapPath (strPathInfo)

 

Dim objFSize, objFile 'Declare two variables

 

'Create new object

Set objFSize = CreateObject ("Scripting.FileSystemObject")

 

'Assign object

Set objFile = objFSize.GetFile(strPhysicalPath)

%>

 

<P><P><div>

  <table border="1" cellpadding="5" width="100%"

    bordercolor="#FFFF00" cellspacing="0"><tr>

     <td width="100%"><font face="Verdana" size="2">

<B>File Name: </B><%= objFile.Name %><BR>

<B>Server Path: </B><%= strPathInfo %><BR>

<B>Physical Path: </B><%= objFile.Path %><BR>

<B>File Size: </B><%= objFile.Size %> bytes<BR>

<B>Date Created: </B><%= objFile.DateCreated %><BR>

<B>Date Last Modified: </B><%= objFile.DateLastModified %><BR>

<B>Date Last Accessed: </B><%= objFile.DateLastAccessed %><BR>

     </font></td></tr></table></div>

 

You should see the Menu.htm page embedded above and the FooterInfo.inc page embedded below the main ArrayForNextIncEx2.asp page. See Include Files, For-Next loops and Arrays in your course textbook.

 

Module 2.6

 

Exercise 2 continued.

1. Don't worry J if this week seemed overwhelming. It is the course's mission and obligation to review these numerous programming concepts. This course is introductory, and if you lack the programming background, you'll be better off just knowing that these programming terms and concepts exist.
2. Try to find, modify or create your own code examples for each type of control statement. Many programmers have a code archive that they share or trade with colleagues.
3. Visit all the links shown on this lesson, and thoroughly review new terminology in the VBScript Language Reference (VBSLR).
4.  Read, paraphrase and outline chapters three through five of the course textbook. (Doing it now will make the rest of this course much easier.)
5. Take notes on this week’s materials and paraphrase it in your own words. Discuss the correct answers to this week’s quiz (shown below) on the Week 2 Student Discussion Board.

 

Module 2.7

 

Quiz 2.

1. ECMAScript includes what two scripting languages?

2. Identify the order of execution for web browsers.

3. Arrays may have what state?

4. Identify looping control statement.

5. Identify valid extension for include files.