Introduction

1.Adding VBScript to Web Pages

Scripting languages, like JavaScript and VBScript, are designed as an extension to HTML. The web browser receives scripts along with the rest of the web document. It is the browser's responsibility to parse and process the scripts. HTML was extended to include a tag that is used to incorporate scripts into HTML-the <SCRIPT> tag.

The <SCRIPT> Tag

You add scripts into your web pages within a pair of


<SCRIPT> tags. The <SCRIPT> tag signifies the 
start of the script section, while </SCRIPT> marks 
the end. An example of this is shown below:

<HTML>
<HEAD>
<TITLE>Working With VBScript</TITLE>
<SCRIPT LANGUAGE="VBScript">
  MsgBox "Welcome to my Web page!"
</SCRIPT>

You can use the SCRIPT element to add VBScript code to an HTML page.

The <SCRIPT> Tag

VBScript code is written within paired <SCRIPT> tags. For example, a procedure to test a delivery date might appear as follows:

<SCRIPT LANGUAGE="VBScript"> 
<!--
   Function CanDeliver(Dt)
      CanDeliver = (CDate(Dt) - Now()) > 2
   End Function
-->
</SCRIPT>

Beginning and ending <SCRIPT> tags surround the code. The LANGUAGE attribute indicates the scripting language. You must specify the language because browsers can use other scripting languages. Notice that the CanDeliver function is embedded in comment tags (<!-- and -->). This prevents browsers that don't understand the <SCRIPT> tag from displaying the code.

Since the example is a general function—it isn't tied to any particular form control—you can include it in the HEAD section of the page:

<HTML>
<HEAD>
<TITLE>Place Your Order</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!--
   Function CanDeliver(Dt)
      CanDeliver = (CDate(Dt) - Now()) > 2
   End Function
-->
</SCRIPT>
</HEAD>
<BODY>
...

You can use SCRIPT blocks anywhere in an HTML page. You can put them in both the BODY and HEAD sections. However, you'll probably want to put all general-purpose scripting code in the HEAD section in order to keep all the code together. Keeping your code in the HEAD section ensures that all code is read and decoded before it's needed by any calls from within the BODY section.

One notable exception to this rule is that you may want to provide inline scripting code within forms to respond to the events of objects in your form. For example, you can embed scripting code to respond to a button click in a form:

<HTML>
<HEAD>
<TITLE>Test Button Events</TITLE>
</HEAD>
<BODY>
<FORM NAME="Form1">
   <INPUT TYPE="Button" NAME="Button1" VALUE="Click">
   <SCRIPT FOR="Button1" EVENT="onClick" LANGUAGE="VBScript">
      MsgBox "Button Pressed!"
   </SCRIPT>
</FORM>
</BODY>
</HTML>

Most of your code will appear in either Sub or Function procedures and will be called only when code you have written causes it to execute. However, you can write VBScript code outside procedures, but still within a SCRIPT block. This code is executed only once, when the HTML page loads. This allows you to initialize data or dynamically change the look of your Web page when it loads.

Handling Non-Supporting Browsers

Not all browsers support scripting languages. Some only support JavaScript. Only Microsoft's Internet Explorer supports VBScript. You might be wondering what happens to your scripts when non-supporting browsers encounter them. Usually browsers will do what they do most frequently with text, they will display your scripts as part of the web page. Obviously, this isn't the result you had hoped for. One simple way to address this problem is to encase your scripts in comment tags (<!-- and -->). Below is our example script as it appears with the addition of the comment tags:

<HTML>
<HEAD>
<TITLE>Working With VBScript</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!--
  MsgBox "Welcome to my Web page!"
-->
</SCRIPT>
</HEAD>
</HTML>

Now, when a browser that does not support VBScript processes this page, it will view your script as a comment and simply ignore it.

Working with Variables

A variable is a named location in computer memory that you can use for storage of data during the execution of your scripts. You can use variables to:

  • Store input from the user gathered via your web page
  • Save data returned from functions
  • Hold results from calculations

An Introduction to Variables

Let's look at a simple VBScript example to clarify the use of variables.

Sub cmdVariables_OnClick
  Dim Name
  Name = InputBox("Enter your name: ")
  MsgBox "The name you entered was " & Name
End Sub

The first line of this example defines a sub procedure associated with the click event of a command button named cmdVariables.

On the second line we declare a variable named Name. We are going to use this variable to store the name of the user when it is entered. The third line uses the InputBox function to first prompt for, and then return, the user's name. You will see more of the InputBox function later in this tutorial. The name it returns is stored in the Name variable.

The fourth line uses the MsgBox function to display the user's name. Finally, the sub procedure completes on line five.

Exactly how, and where, variables are stored is not important. What you use them for, and how you use them is important. That is what we will be looking at next.

Declaring Variables

There are two methods for declaring variables in VBScript, explicitly and implicitly. You usually declare variables explicitly with the Dim statement:

Dim Name

This statement declares the variable Name. You can also declare multiple variables on one line as shown below, although it is preferable to declare each variable separately:

Dim Name, Address, City, State

Variables can be declared implicitly by simply using the variable name within your script. This practice is not recommended. It leads to code that is prone to errors and more difficult to debug.

You can force VBScript to require all variables to be explicitly declared by including the statement Option Explicit at the start of every script. Any variable that is not explicitly declared will then generate an error.

Variable Naming Rules

When naming variables the following rules apply:

  • They must begin with an alphabetic character
  • They cannot contain embedded periods
  • They must be unique within the same scope. There is more on scopes later in this lesson
  • They must be no longer than 255 characters

Variants and Subtypes

VBScript has a single data type called a variant. Variants have the ability to store different types of data. The types of data that a variant can store are referred to as subtypes. The table below describes the subtypes supported by VBScript.

 

Subtype Description of Uses for Each Subtype
Byte Integer numbers between 0 to 255
Boolean True and False
Currency Monetary values
Date Date and time
Double Extremely large numbers with decimal points
Empty The value that a variant holds before being used
Error An error number
Integer Large integers between -32,768 and 32,767
Long Extremely large integers (-2,147,483,648 and 2,147,483,647)
Object Objects
Null No valid data
Single Large numbers with decimal points
String Character strings
What Are VBScript Data Types?

VBScript has only one data type called a Variant. A Variant is a special kind of data type that can contain different kinds of information, depending on how it's used. Because Variant is the only data type in VBScript, it's also the data type returned by all functions in VBScript.

At its simplest, a Variant can contain either numeric or string information. A Variant behaves as a number when you use it in a numeric context and as a string when you use it in a string context. That is, if you're working with data that looks like numbers, VBScript assumes that it is numbers and does the thing that is most appropriate for numbers. Similarly, if you're working with data that can only be string data, VBScript treats it as string data. Of course, you can always make numbers behave as strings by enclosing them in quotation marks (" ").

Variant Subtypes

Beyond the simple numeric or string classifications, a Variant can make further distinctions about the specific nature of numeric information. For example, you can have numeric information that represents a date or a time. When used with other date or time data, the result is always expressed as a date or a time. Of course, you can also have a rich variety of numeric information ranging in size from Boolean values to huge floating-point numbers. These different categories of information that can be contained in a Variant are called subtypes. Most of the time, you can just put the kind of data you want in a Variant, and the Variant behaves in a way that is most appropriate for the data it contains.

The following table shows the subtypes of data that a Variant can contain.

Subtype Description
Empty Variant is uninitialized. Value is 0 for numeric variables or a zero-length string ("") for string variables.
Null Variant intentionally contains no valid data.
Boolean Contains either True or False.
Byte Contains integer in the range 0 to 255.
Integer Contains integer in the range -32,768 to 32,767.
Currency -922,337,203,685,477.5808 to 922,337,203,685,477.5807.
Long Contains integer in the range -2,147,483,648 to 2,147,483,647.
Single Contains a single-precision, floating-point number in the range -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values.
Double Contains a double-precision, floating-point number in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.
Date (Time) Contains a number that represents a date between January 1, 100 to December 31, 9999.
String Contains a variable-length string that can be up to approximately 2 billion characters in length.
Object Contains an object.
Error Contains an error number.

You can use conversion functions to convert data from one subtype to another. In addition, the VarType function returns information about how your data is stored within a Variant.

Assigning Values

You assign a value to a variable by using the following format:

Variable_name = value

The following examples demonstrate assigning values to variables:


Name = "Larry Roof"
HoursWorked = 50
Overtime = True

Scope of Variables

The scope of a variable dictates where it can be used in your script. A variable's scope is determined by where it is declared. If it is declared within a procedure, it is referred to as a procedure-level variable and can only be used within that procedure. If it is declared outside of any procedure, it is a script-level variable and can be used throughout the script.

The example below demonstrates both script-level and procedure-level variables.

<SCRIPT>
  Dim counter
  Sub cmdButton_onClick
    Dim temp
  End Sub
</SCRIPT>

The variable counter is a script-level variable and can be utilized throughout the script. The variable temp exists only within the cmdButton_onClick sub-procedure.

Constants

What Is a Constant?

A constant is a meaningful name that takes the place of a number or string and never changes. VBScript defines a number of intrinsic constants. You can get information about these intrinsic constants from the VBScript Language Reference.

Creating Constants

You create user-defined constants in VBScript using the Const statement. Using the Const statement, you can create string or numeric constants with meaningful names and assign them literal values. For example:

Const MyString = "This is my string."
Const MyAge = 49

Note that the string literal is enclosed in quotation marks (" "). Quotation marks are the most obvious way to differentiate string values from numeric values. Date literals and time literals are represented by enclosing them in number signs (#). For example:

Const CutoffDate = #6-1-97#

You may want to adopt a naming scheme to differentiate constants from variables. This will prevent you from trying to reassign constant values while your script is running. For example, you might want to use a "vb" or "con" prefix on your constant names, or you might name your constants in all capital letters. Differentiating constants from variables eliminates confusion as you develop more complex scripts.

Arrays

The VBScript language provides support for arrays. You declare an array using the Dim statement, just as you did with variables:

Dim States(50)

The statement above creates an array with 51 elements. Why 51? Because VBScript arrays are zero-based, meaning that the first array element is indexed 0 and the last is the number specified when declaring the array.

You assign values to the elements of an array just as you would a variable, but with an additional reference (the index) to the element in which it will be stored:

States(5) = "California" States(6) = "New York"

Arrays can have multiple dimensions-VBScript supports up to 60. Declaring a two dimensional array for storing 51 states and their capitals could be done as follows:

Dim StateInfo(50,1)

To store values into this array you would then reference both dimensions.

StateInfo(18,0) = "Michigan" StateInfo(18,1) = "Lansing"

VBScript also provides support for arrays whose size may need to change as the script is executing. These arrays are referred to as dynamic arrays. A dynamic array is declared without specifying the number of elements it will contain:

Dim Customers()

The ReDim statement is then used to change the size of the array from within the script:

ReDim Customers(100)

There is no limit to the number of times an array can be re-dimensioned during the execution of a script. To preserve the contents of an array when you are re-dimensioning, use the Preserve keyword:

ReDim Preserve Customers(100) .

2.Objects and VBScript

Objects, both in the form of Java applets and ActiveX controls, enhance the functionality that is provided with HTML. By using VBScript you can extend the capabilities of these controls, integrating and manipulating them from within your scripts. In this lesson we will look at how you can utilize the power of objects with VBScript.

Scripting with objects involves two steps:

  • Adding the object to your web page using HTML
  • Writing script procedures to respond to events that the object provides

Adding Objects to Your Web Pages

Since this is a VBScript tutorial, rather than an HTML tutorial, we will offer only a limited discussion of how to add an object to a web page. Objects, whether they're Java applets or ActiveX controls are added to a page with the <OBJECT> tag. The properties, or characteristics, of the object are configured using the <PARAM> tag. Typically you will see an object implemented using a single <OBJECT> tag along with several <PARAM> tags. The following HTML code demonstrates how an ActiveX control might appear when added to a page:

<OBJECT ID="lblTotalPay" WIDTH=45 HEIGHT=24 
CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0">
<PARAM NAME="ForeColor" VALUE="0">
<PARAM NAME="BackColor" VALUE="16777215">
<PARAM NAME="Caption" VALUE="">
<PARAM NAME="Size" VALUE="1582;635">
<PARAM NAME="SpecialEffect" VALUE="2">
<PARAM NAME="FontHeight" VALUE="200">
<PARAM NAME="FontCharSet" VALUE="0">
<PARAM NAME="FontPitchAndFamily" VALUE="2">
<PARAM NAME="FontWeight" VALUE="0">

Linking VBScript with Objects

Once you have added a control to your web page, it can be configured, manipulated and responded to through its properties, methods and events. Properties are the characteristics of an object. They include items like a caption, the foreground color and the font size. Methods cause an object to perform a task. Events are actions that are recognized by an object. For instance, a command button recognizes an onclick event.

Note

The Script Wizard found in the Microsoft ActiveX Control Pad can be used to identify events provided by a control, and to generate script to respond to these events.

For the most part, you will be focusing on properties and events. An example of setting properties for a label control is shown in the following example.

<SCRIPT LANGUAGE="VBScript">
Sub cmdCalculatePay_onClick
  Dim HoursWorked
  Dim PayRate
  Dim TotalPay
  HoursWorked = InputBox("Enter hours worked: ")
  PayRate = InputBox("Enter pay rate: ")
  TotalPay = HoursWorked * PayRate
  lblTotalPay.caption = TotalPay
End Sub
</SCRIPT>

The caption property of the label control, lblTotalPay, is set equal to the results of our calculation with the script line:

document.frmPayrate.lblTotalPay.caption = TotalPay

Object properties are referenced within your scripts using the same format shown in Exercise 2.

3

VBScript allows you to control how your scripts process data through the use of conditional and looping statements. By using conditional statements you can develop scripts that evaluate data and use criteria to determine what tasks to perform. Looping statements allow you to repetitively execute lines of a script. Each offers benefits to the script developer in the process of creating more complex and functional web pages.

Conditional Statements

VBScript provides two forms of conditional statements:

conditional and looping statements

VBScript allows you to control how your scripts process data through the use of e="CH21_20_3"/>

If..Then..Else

The If..Then..Else statement is used, first to evaluate a condition to see if it is true or false and second, depending upon the condition, to execute a statement or set of statements. Rather than discussing an If statement in theory, we will examine some examples to see how they work.

The simplest version of an If statement is one that contains only a condition and a single statement:

If AmountPurchased > 10000 Then 
    DiscountAmount = AmountPurchased * .10

In this example statement the condition is:

If AmountPurchased > 10000

which simply checks to see if the contents of the variable AmountPurchased is greater than ten thousand. If it is, the condition is true. In this simple version of the If statement when the condition is true the following statement is executed:

DiscountAmount = AmountPurchased * .10

Next we will look at a more complicated version of the If statement. In this version we will perform a series of statements when the condition is true:

If AmountPurchased > 10000 Then 
  DiscountAmount = AmountPurchased * .10
  Subtotal = AmountPurchased - DiscountAmount
End If

In this form of the If statement, one or more statements can be executed when the condition is true, by placing them between the If statement on top and the End If statement on the bottom.

The next form of the If statement uses the If..Then..Else format. This version of the If statement differs from the two previous versions in that it will perform one set of statements if the condition is true and another set when the condition is false:

If AmountPurchased > 10000 Then 
  DiscountAmount = AmountPurchased * .10
  Subtotal = AmountPurchased - DiscountAmount
Else
  HandlingFee = AmountPurchased *.03
  Subtotal = AmountPurchased + HandlingFee
End If

In this example when the condition is true, that is the customer's order is over $10,000, they receive a 10% discount. When the order is under $10,000, they are charged a 3% handling fee.

The final version of the If statement that we will look at is the If..Then..Else If. In this form the If statement checks each of the conditions until it either finds one that is true or an Else statement:

If AmountPurchased > 10000 Then 
  DiscountAmount = AmountPurchased * .10
  Subtotal = AmountPurchased - DiscountAmount
Else If AmountPurchased > 5000 Then
  DiscountAmount = AmountPurchased * .05
  Subtotal = AmountPurchased - DiscountAmount
Else
  HandlingFee = AmountPurchased *.03
  Subtotal = AmountPurchased + HandlingFee
End If

In this example the customer receives a 10%discount for orders over $10000, a 5% discount for orders over $5000 and a handling fee of 3% for orders under $5000.

As you see, VBScript offers you plenty of options when it comes to If statements.

Select Case

The Select Case statement provides an alternative to the If..Then..Else statement, providing additional control and readability when evaluating complex conditions. It is well suited for situations where there are a number of possible conditions for the value being checked. Like the If statement the Select Case structure checks a condition, and based upon that condition being true, executes a series of statements.

The syntax of the Select Case statement is:

Select Case condition
  Case value
  Case value
  ...
  Case Else
End Select

For example, the following Select statement assigns different shipping fees based upon the State where the order is being sent:

Select Case Document.frmOrder.txtState.Value
  Case "California"
    ShippingFee= .04
  Case "Florida"
    ShippingFee = .03
  Case Else
    ShippingFee = .02
End Select

The Select Case statement checks each of the Case statements until it finds one that will result in the condition being true. If none are found to be true, it executes the statements within the Case Else.

Using Loops to Repeat Code

Looping allows you to run a group of statements repeatedly. Some loops repeat statements until a condition is False; others repeat statements until a condition is True. There are also loops that repeat statements a specific number of times.

The following looping statements are available in VBScript:

  • Do...Loop: Loops while or until a condition is True.
  • While...Wend: Loops while a condition is True.
  • For...Next: Uses a counter to run statements a specified number of times.
  • For Each...Next: Repeats a group of statements for each item in a collection or each element of an array.
Using Do Loops

You can use Do...Loop statements to run a block of statements an indefinite number of times. The statements are repeated either while a condition is True or until a condition becomes True.

Repeating Statements While a Condition is True

Use the While keyword to check a condition in a Do...Loop statement. You can check the condition before you enter the loop (as shown in the following ChkFirstWhile example), or you can check it after the loop has run at least once (as shown in the ChkLastWhile example). In the ChkFirstWhile procedure, if myNum is set to 9 instead of 20, the statements inside the loop will never run. In the ChkLastWhile procedure, the statements inside the loop run only once because the condition is already False.

Sub ChkFirstWhile()
     Dim counter, myNum
     counter = 0
     myNum = 20
     Do While myNum > 10
         myNum = myNum - 1
         counter = counter + 1
     Loop
     MsgBox "The loop made " & counter & " repetitions."
 End Sub

 Sub ChkLastWhile()
     Dim counter, myNum
     counter = 0
     myNum = 9
     Do
         myNum = myNum - 1
         counter = counter + 1
     Loop While myNum > 10
     MsgBox "The loop made " & counter & " repetitions."
 End Sub
Repeating a Statement Until a Condition Becomes True

You can use the Until keyword in two ways to check a condition in a Do...Loop statement. You can check the condition before you enter the loop (as shown in the following ChkFirstUntil example), or you can check it after the loop has run at least once (as shown in the ChkLastUntil example). As long as the condition is False, the looping occurs.

Sub ChkFirstUntil()
     Dim counter, myNum
     counter = 0
     myNum = 20
     Do Until myNum = 10
         myNum = myNum - 1
         counter = counter + 1
     Loop
     MsgBox "The loop made " & counter & " repetitions."
 End Sub

 Sub ChkLastUntil()
     Dim counter, myNum
     counter = 0
     myNum = 1
     Do
         myNum = myNum + 1
         counter = counter + 1
     Loop Until myNum = 10
     MsgBox "The loop made " & counter & " repetitions."
 End Sub
Exiting a Do...Loop Statement from Inside the Loop

You can exit a Do...Loop by using the Exit Do statement. Because you usually want to exit only in certain situations, such as to avoid an endless loop, you should use the Exit Do statement in the True statement block of an If...Then...Else statement. If the condition is False, the loop runs as usual.

In the following example, myNum is assigned a value that creates an endless loop. The If...Then...Else statement checks for this condition, preventing the endless repetition.

Sub ExitExample()
     Dim counter, myNum
     counter = 0
     myNum = 9
     Do Until myNum = 10
         myNum = myNum - 1
         counter = counter + 1
         If myNum < 10 Then Exit Do
     Loop
     MsgBox "The loop made " & counter & " repetitions."
 End Sub
Using While...Wend

The While...Wend statement is provided in VBScript for those who are familiar with its usage. However, because of the lack of flexibility in While...Wend, it is recommended that you use Do...Loop instead.

Using For...Next

You can use For...Next statements to run a block of statements a specific number of times. For loops, use a counter variable whose value is increased or decreased with each repetition of the loop.

For example, the following procedure causes a procedure called MyProc to execute 50 times. The For statement specifies the counter variable x and its start and end values. The Next statement increments the counter variable by 1.

Sub DoMyProc50Times()
     Dim x
     For x = 1 To 50
         MyProc
     Next
 End Sub

Using the Step keyword, you can increase or decrease the counter variable by the value you specify. In the following example, the counter variable j is incremented by 2 each time the loop repeats. When the loop is finished, total is the sum of 2, 4, 6, 8, and 10.

Sub TwosTotal()
     Dim j, total
     For j = 2 To 10 Step 2
         total = total + j
     Next
     MsgBox "The total is " & total
 End Sub

To decrease the counter variable, you use a negative Step value. You must specify an end value that is less than the start value. In the following example, the counter variable myNum is decreased by 2 each time the loop repeats. When the loop is finished, total is the sum of 16, 14, 12, 10, 8, 6, 4, and 2.

 

Sub NewTotal()
     Dim myNum, total
     For myNum = 16 To 2 Step -2
         total = total + myNum
     Next
     MsgBox "The total is " & total
 End Sub

You can exit any For...Next statement before the counter reaches its end value by using the Exit For statement. Because you usually want to exit only in certain situations, such as when an error occurs, you should use the Exit For statement in the True statement block of an If...Then...Else statement. If the condition is False, the loop runs as usual.

 

Using For Each...Next

A For Each...Next loop is similar to a For...Next loop. Instead of repeating the statements a specified number of times, a For Each...Next loop repeats a group of statements for each item in a collection of objects or for each element of an array. This is especially helpful if you don't know how many elements are in a collection.

In the following HTML code example, the contents of a Dictionary object is used to place text in several text boxes:

 <HTML>
 <HEAD><TITLE>Forms and Elements</TITLE></HEAD>

 <SCRIPT LANGUAGE="VBScript">
 <!--
 Sub cmdChange_OnClick
    Dim d                   'Create a variable
    Set d = CreateObject("Scripting.Dictionary")
    d.Add "0", "Athens"     'Add some keys and items
    d.Add "1", "Belgrade"
    d.Add "2", "Cairo"

    For Each I in d
        Document.frmForm.Elements(I).Value = D.Item(I)
    Next
 End Sub
 -->

 </SCRIPT>
 <BODY>
 <CENTER>

 <FORM NAME="frmForm"

 <Input Type = "Text"><p>
 <Input Type = "Text"><p>
 <Input Type = "Text"><p>
 <Input Type = "Text"><p>
 <Input Type = "Button" NAME="cmdChange" VALUE="Click Here"><p>
 </FORM>
 </CENTER>
 </BODY>
 </HTML>

4.Procedures

Kinds of Procedures

In VBScript there are two kinds of procedures; the Sub procedure and the Function procedure.

Sub Procedures

A Sub procedure is a series of VBScript statements, enclosed by Sub and End Sub statements, that perform actions but don't return a value. A Sub procedure can take arguments (constants, variables, or expressions that are passed by a calling procedure). If a Sub procedure has no arguments, its Sub statement must include an empty set of parentheses ().

The following Sub procedure uses two intrinsic, or built-in, VBScript functions, MsgBox and InputBox, to prompt a user for some information. It then displays the results of a calculation based on that information. The calculation is performed in a Function procedure created using VBScript. The Function procedure is shown after the following discussion.

 Sub ConvertTemp()
    temp = InputBox("Please enter the temperature in degrees F.", 1)
    MsgBox "The temperature is " & Celsius(temp) & " degrees C."
 End Sub

Function Procedures

A Function procedure is a series of VBScript statements enclosed by the Function and End Function statements. A Function procedure is similar to a Sub procedure, but can also return a value. A Function procedure can take arguments (constants, variables, or expressions that are passed to it by a calling procedure). If a Function procedure has no arguments, its Function statement must include an empty set of parentheses. A Function returns a value by assigning a value to its name in one or more statements of the procedure. The return type of a Function is always a Variant.

In the following example, the Celsius function calculates degrees Celsius from degrees Fahrenheit. When the function is called from the ConvertTemp Sub procedure, a variable containing the argument value is passed to the function. The result of the calculation is returned to the calling procedure and displayed in a message box.

Sub ConvertTemp()
     temp = InputBox("Please enter the temperature in degrees F.", 1)
     MsgBox "The temperature is " & Celsius(temp) & " degrees C."
 End Sub

 Function Celsius(fDegrees)
     Celsius = (fDegrees - 32) * 5 / 9
 End Function

Getting Data into and out of Procedures

Each piece of data is passed into your procedures using an argument. Arguments serve as placeholders for the data you want to pass into your procedure. You can name your arguments anything that is valid as a variable name. When you create a procedure using either the Sub statement or the Function statement, parentheses must be included after the name of the procedure. Any arguments are placed inside these parentheses, separated by commas. For example, in the following example, fDegrees is a placeholder for the value being passed into the Celsius function for conversion:

 Function Celsius(fDegrees)
    Celsius = (fDegrees - 32) * 5 / 9
 End Function

To get data out of a procedure, you must use a Function. Remember, a Function procedure can return a value; a Sub procedure can't.

Using Sub and Function Procedures in Code

A Function in your code must always be used on the right side of a variable assignment or in an expression. For example:

 

 Temp = Celsius(fDegrees)
or

 MsgBox "The Celsius temperature is " & Celsius(fDegrees) & " degrees."

To call a Sub procedure from another procedure, you can just type the name of the procedure along with values for any required arguments, each separated by a comma. The Call statement is not required, but if you do use it, you must enclose any arguments in parentheses.

The following example shows two calls to the MyProc procedure. One uses the Call statement in the code; the other doesn't. Both do exactly the same thing.

Call MyProc(firstarg, secondarg)
 MyProc firstarg, secondarg

Notice that the parentheses are omitted in the call when the Call statement isn't used

5 - DOM GrabBag

Using VBScript with Forms

As the popularity of web page forms increase, so does the need to be able to validate data before the client browser submits it to the web server. As a scripting language, VBScript is well suited for this task. Once the form has been validated, the same script can be used to forward the data on to the server. In this lesson we will look at both the process of validating and submitting forms.

Validating Your Forms

The process of validating forms involves checking the form to see if:

  • All of the required data is proved
  • The data provided is valid

Meticulous data validation scripts can be tedious to code but are well worth their return in verifying the quality of the data.

The validation example that we will be examining does not contain anything new in the way of VBScript. We are simply using the elements that we have learned in the previous lessons in a new way. Before reading any further you may find if beneficial to ponder how you would validate an HTML form using the VBScript techniques that you have learned.

Okay, are you through pondering? Let's look at an example to give you an idea of what is possible when it comes to validating forms.

Checking Form Input

This example is pretty simple. It has a single field in which the user can enter their age and a single command button that is used to submit their age to the server. A copy of this example can be found in exam_5a.htm.

<HTML>
<HEAD>
<TITLE>Working With VBScript: Example 5a</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!-- Instruct non-IE browsers to skip over VBScript modules.
Option Explicit
Sub cmdSubmit_OnClick
' Check to see if the user entered anything.
  If (Len(document.frmExample5a.txtAge.value) = 0) Then
    MsgBox "You must enter your age before submitting."
    Exit Sub
  End If
' Check to see if the user entered a number.
  If (Not(IsNumeric(document.frmExample5a.txtAge.value))) Then
    MsgBox "You must enter a number for your age."
    Exit Sub
  End If
' Check to see if the age entered is valid.
  If (document.frmExample5a.txtAge.value < 0) Or _
     (document.frmExample5a.txtAge.value > 100) Then
    MsgBox "The age you entered is invalid."
    Exit Sub
  End If
' Data looks okay so submit it.
  MsgBox "Thanks for providing your age."
  document.frmExample5a.submit
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H1>A VBScript Example on Variables</H1>
<P> This example demonstrates validation techniques in VBScript. </P>
<FORM NAME="frmExample5a">
  <TABLE>
    <TR>
      <TD>Enter your age:</TD>
      <TD><INPUT TYPE="Text" NAME="txtAge" SIZE="2">
    <TR>
      <TD><INPUT TYPE="Button" NAME="cmdSubmit" VALUE="Submit"></TD>
      <TD></TD>
    </TR>
  </TABLE>
</FORM>
</BODY>
</HTML>

How It Works

The heart of this validation script is found in the click event procedure for the cmdSubmit command button. We start by checking if the user entered anything at all into the field using VBScript's Len function. This function returns the length of a string. If the length is 0, the data is invalid. We inform the user and exit the submit procedure via the Exit Sub statement:

' Check to see if the user entered anything.
  If (Len(document.frmExample5a.txtAge.value) = 0) Then
    MsgBox "You must enter your age before submitting."
    Exit Sub
  End If

Next we check to see if what the user entered is a numeric value. The VBScript function IsNumeric returns a true value when it is a number. If not, we tell the user and exit:

' Check to see if the user entered a number.
  If (Not(IsNumeric(document.frmExample5a.txtAge.value))) Then
    MsgBox "You must enter a number for your age."
    Exit Sub
  End If

Our final check involves verifying that the age they entered seems reasonable for our environment. I have determined that no age less than 0 or greater than 100 is acceptable. Using an If..Then statement we can check the value of the input field against this criteria:

' Check to see if the age entered is valid.
  If (document.frmExample5a.txtAge.value < 0) Or _
     (document.frmExample5a.txtAge.value > 100) Then
    MsgBox "The age you entered is invalid."
    Exit Sub
  End If

That's it. While this example is by no means the most detailed validation script you will encounter it provides you with a basis of what is possible with VBScript.

Submitting Your Forms

Compared to validation, the process of submitting a form is simple. In our example we've used a normal HTML button with the Submit caption that is tied to an event procedure that both validates and at the same time submits the form. In Chapter 5, we've demonstrated how to use function MyButton_onSubmit, as an alternative.

The code that we would have to add to our previous example to submit the form is shown below:

' Data looks okay so submit it.
  MsgBox "Thanks for providing your age."
  document.frmExample5a.submit

The MsgBox statement lets the user know that their data has been processed. The form is then submitted by invoking the Submit method of the form object. As we saw in lesson 3 on objects, methods cause an object to perform a task. Here we are using the submit method of our form to cause the form to submit its data, just as if we had used a submit control.

You can use Visual Basic Scripting Edition to do much of the form processing that you'd usually have to do on a server. You can also do things that just can't be done on the server.

Here's an example of simple client-side validation. The HTML code is for a text box and a button. If you use Microsoft® Internet Explorer to view the page produced by the following code, you'll see a small text box with a button next to it.

<HTML>
<HEAD><TITLE>Simple Validation</TITLE>
<SCRIPT LANGUAGE="VBScript"> 
<!--
Sub Submit_OnClick
  Dim TheForm
  Set TheForm = Document.ValidForm
  If IsNumeric(TheForm.Text1.Value) Then
    If TheForm.Text1.Value < 1 Or TheForm.Text1.Value > 10 Then
      MsgBox "Please enter a number between 1 and 10."
    Else
      MsgBox "Thank you."
    End If
  Else
    MsgBox "Please enter a numeric value."
  End If
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3>Simple Validation</H3><HR>
<FORM NAME="ValidForm">
Enter a value between 1 and 10: 
<INPUT NAME="Text1" TYPE="TEXT" SIZE="2">
<INPUT NAME="Submit" TYPE="BUTTON" VALUE="Submit">
</FORM>
</BODY>
</HTML>

The difference between this text box and the examples on A Simple VBScript Page is that the Value property of the text box is used to check the entered value. To get the Value property, the code has to qualify the reference to the name of the text box.

You can always write out the full reference Document.ValidForm.Text1. However, where you have multiple references to form controls, you'll want to do what was done here. First declare a variable. Then use the Set statement to assign the form to the variable TheForm. A regular assignment statement, such as Dim, doesn't work here; you must use Set to preserve the reference to an object.

Using Numeric Values

Notice that the example directly tests the value against a number: it uses the IsNumeric function to make sure the string in the text box is a number. Although VBScript automatically converts strings and numbers, it's always a good practice to test a user-entered value for its data subtype and to use conversion functions as necessary. When doing addition with text box values, convert the values explicitly to numbers because the plus sign (+) operator represents both addition and string concatenation. For example, if Text1 contains "1" and Text2 contains "2", you see the following results:

A = Text1.Value + Text2.Value		' A is "12"
A = CDbl(Text1.Value) + Text2.Value	' A is 3
Validating and Passing Data Back to the Server

The simple validation example uses a plain button control. If a Submit control was used, the example would never see the data to check it—everything would go immediately to the server. Avoiding the Submit control lets you check the data, but it doesn't submit the data to the server. That requires an additional line of code:

<SCRIPT LANGUAGE="VBScript"> 
<!--
Sub Submit_OnClick
  Dim TheForm
  Set TheForm = Document.ValidForm
  If IsNumeric(TheForm.Text1.Value) Then
    If TheForm.Text1.Value < 1 Or TheForm.Text1.Value > 10 Then
      MsgBox "Please enter a number between 1 and 10."
    Else
      MsgBox "Thank you."
      TheForm.Submit	' Data correct; send to server.
    End If
  Else
    MsgBox "Please enter a numeric value."
  End If
End Sub
-->
</SCRIPT>

To send the data to the server, the code invokes the Submit method on the form object when the data is correct. From there, the server handles the data just as it otherwise would—except that the data is correct before it gets there. You'll find complete information about the Submit method and other methods on the Internet Explorer Scripting Object Model page.

So far, you've seen only the standard HTML <FORM> objects. Internet Explorer also lets you exploit the full power of ActiveX™ controls (formerly called OLE controls) and Java™ objects.

Built-In Functions

VBScript ships with many functions that you can use to complete your scripts. These functions are highly reliable and can tremendously reduce your work. This means that, before creating your own procedure or function, first make sure it has not been written already because if an existing function already implements the behavior you want to apply, you should such a function.

Because VBScript is an interpreted language (and not a compiled language), all of the possible built-in functions are already known to the browser. Therefore, you don't need to include a file or library.

The best place to find out what functions already exist is by consulting the MSDN library or web site for its documentation.

Conversion Functions

We saw already that the users of your web pages will be presented with objects called controls. These objects allow the user to type values or select something from a list. Anything the user types in a text-based field is primarily considered as a string. Before performing any type of operation that involves such a value, you should make sure you can identify what kind of value it is. For example, you shouldn't try to multiply a string by a date such as FirstName * January 16. Although you will not be able to avoid every single type of problem that could occur in a page, you can reduce errors by checking the value that a control holds.

The first thing you should do with a value retrieved from a control is to convert it to the appropriate type. There are various conversion functions adapted to the different possible kinds of values. The general syntax of the conversion functions is:

ReturnType = Function(Expression)

The expression could be of any kind, depending on how the expression would be supplied. For example, it could be a string or value the user would have entered in form. It could also be the result of a calculation performed on another procedure or function. The function would take such a value, string, or expression and attempt to convert. If the conversion is successful, the function would return a new value that is of the type specified by the ReturnType in our syntax.

The conversion functions are as follows:
Function  
Name Return Type Description
CBool Boolean Converts an expression into a Boolean value
CByte Byte Converts an expression into Byte number
CDate Date Converts and expression into a date or time value
CDbl Double Converts an expression into a flowing-point (decimal) number
CInt Integer Converts an expression into an integer (natural) number
CCur Currency Converts an expression into a currency (monetary) value
CLng Long Converts an expression into a long integer (a large natural) number
CSng Single Converts an expression into a flowing-point (decimal) number
CStr String Converts an expression into a string

Practical Learning: 

Start your text editor.
 In the empty file, type the following:

<html>
<head>
<Script Language="VBScript">
<!--
Sub GiveFocus
  Document.EmployeesPayroll.txtFirstName.Focus()
End Sub
-->
</Script>

<title>Employees Payroll</title>
</head>

<body>

<h1>Oddenton Auto Repair</h1>
<h2>Employees Payroll</h2>
<form name="EmployeesPayroll" method="POST">
  <table border="0" width="548">
    <tr>
      <td width="104">First Name:</td>
      <td width="430"><input type="text" name="txtFirstName" size="20"></td>
    </tr>
    <tr>
      <td width="104">LastName:</td>
      <td width="430"><input type="text" name="txtLastName" size="20"></td>
    </tr>
  </table>
 
  <table border="0" width="548">
    <tr>
      <td width="104">Hourly Salary</td>
      <td width="428"><input type="text" name="txtHourlySalary" size="10"value="0.00"></td>
    </tr>
  </table>
  <table border="0" width="563">
    <tr>
      <td width="124">Weekly Hours</td>
      <td width="62" align="center">Mon</td>
      <td width="62" align="center">Tue</td>
      <td width="62" align="center">Wed</td>
      <td width="62" align="center">Thu</td>
      <td width="62" align="center">Fri</td>
      <td width="62" align="center">Sat</td>
      <td width="62" align="center">Sun</td>
    </tr>
    <tr>
      <td width="124"></td>
      <td width="62" align="center"><input type="text" name="txtMon" size="6" value="0.00"></td>
      <td width="62" align="center"><input type="text" name="txtTue" size="6" value="0.00"></td>
      <td width="62" align="center"><input type="text" name="txtWed" size="6" value="0.00"></td>
      <td width="62" align="center"><input type="text" name="txtThu" size="6" value="0.00"></td>
      <td width="62" align="center"><input type="text" name="txtFri" size="6" value="0.00"></td>
      <td width="62" align="center"><input type="text" name="txtSat" size="6" value="0.00"></td>
      <td width="62" align="center"><input type="text" name="txtSun" size="6" value="0.00"></td>
    </tr>
  </table>
  <table border="0" width="558">
    <tr>
      <td width="104"></td>
      <td width="440">
        <p><input type="button" value="Process" name="btnProcess">
           &nbsp;&nbsp;
   <input type="reset" value="Reset" name="B2">
        </p>
      </td>
    </tr>
  </table>
</form>
</body>

</html>

3.Save the file as payroll2.htm in the vbstutorial folder and preview it in the browser:

  •  
  • After previewing the page, return to your text editor.
  • To perform calculations that involve values stored in text boxes, change the file as follows:
      <html>
<head>
<Script Language="VBScript">
<!--
' -- This procedure gives focus to the First Name text box
Sub GiveFocus
  Document.EmployeesPayroll.txtFirstName.Focus()
End Sub

' This function retrieves the first and last names
' It concatenates them and returns a full name
Function GetFullName()
  Dim FirstName, LastName

  FirstName = Document.EmployeesPayroll.txtFirstName.Value
  LastName  = Document.EmployeesPayroll.txtLastName.Value

  GetFullName = LastName & ", " & FirstName
End Function

' This function uses an hourly salary and the number of hours in a week
' It calculates the total earnings for the week
Function CalculateWeeklySalary(HourlySalary, WeeklyHours)
  CalculateWeeklySalary = HourlySalary * WeeklyHours
End Function

' This is the central procedure of the script
' It processes the form and displays the values in the other form
Sub ProcessPayroll()
  Dim dMon, dTue, dWed, dThu, dFri, dSat, dSun, TotalHours
  Dim HourlySalary, WeeklySalary
  Dim FullName

  dMon = CDbl(Document.EmployeesPayroll.txtMon.Value)
  dTue = CDbl(Document.EmployeesPayroll.txtTue.Value)
  dWed = CDbl(Document.EmployeesPayroll.txtWed.Value)
  dThu = CDbl(Document.EmployeesPayroll.txtThu.Value)
  dFri = CDbl(Document.EmployeesPayroll.txtFri.Value)
  dSat = CDbl(Document.EmployeesPayroll.txtSat.Value)
  dSun = CDbl(Document.EmployeesPayroll.txtSun.Value)

  HourlySalary = Document.EmployeesPayroll.txtHourlySalary.Value

  TotalHours   = dMon + dTue + dWed + dThu + dFri + dSat + dSun
  WeeklySalary = CalculateWeeklySalary(HourlySalary, TotalHours)
  FullName     = GetFullName()


  PayrollResults.txtFullName.Value       = FullName
  PayrollResults.txtWeeklyEarnings.Value = "$" & WeeklySalary
End Sub
-->
</Script>

<title>Employees Payroll</title>
</head>

<body OnLoad="GiveFocus()">

<h1>Odenton Auto Repair</h1>
<h2>Employees Payroll</h2>
<form name="EmployeesPayroll" method="POST">
  <table border="0" width="548">
    <tr>
      <td width="104">First Name:</td>
      <td width="430"><input type="text" name="txtFirstName" size="20"></td>
    </tr>
    <tr>
      <td width="104">LastName:</td>
      <td width="430"><input type="text" name="txtLastName" size="20"></td>
    </tr>
  </table>
 
  <table border="0" width="548">
    <tr>
      <td width="104">Hourly Salary</td>
      <td width="428"><input type="text" name="txtHourlySalary" size="10" value="0.00"></td>
    </tr>
  </table>
  <table border="0" width="563">
    <tr>
      <td width="124">Weekly Hours</td>
      <td width="62" align="center">Mon</td>
      <td width="62" align="center">Tue</td>
      <td width="62" align="center">Wed</td>
      <td width="62" align="center">Thu</td>
      <td width="62" align="center">Fri</td>
      <td width="62" align="center">Sat</td>
      <td width="62" align="center">Sun</td>
    </tr>
    <tr>
      <td width="124"></td>
      <td width="62" align="center"><input type="text" name="txtMon" size="6" value="0.00"></td>
      <td width="62" align="center"><input type="text" name="txtTue" size="6" value="0.00"></td>
      <td width="62" align="center"><input type="text" name="txtWed" size="6" value="0.00"></td>
      <td width="62" align="center"><input type="text" name="txtThu" size="6" value="0.00"></td>
      <td width="62" align="center"><input type="text" name="txtFri" size="6" value="0.00"></td>
      <td width="62" align="center"><input type="text" name="txtSat" size="6" value="0.00"></td>
      <td width="62" align="center"><input type="text" name="txtSun" size="6" value="0.00"></td>
    </tr>
  </table>
  <table border="0" width="558">
    <tr>
      <td width="104"></td>
      <td width="440">
        <p><input type="button" value="Process" name="btnProcess" OnClick="ProcessPayroll()">
           &nbsp;&nbsp;
   <input type="reset" value="Reset" name="B2">
        </p>
      </td>
    </tr>
  </table>
</form>

<hr>

<form name="PayrollResults">
<table border="0" width="546">
  <tr>
    <td width="113">Full Name:</td>
    <td width="419"><input type="text" name="txtFullName" size="20"></td>
  </tr>
</table>
<table border="0" width="545">
  <tr>
    <td width="112">Weekly Earnings:</td>
    <td width="419"><input type="text" name="txtWeeklyEarnings" size="20" value="$0.00"></td>
  </tr>
</table>
</form>

</body>

</html>

Save the file and preview it in the browser. Type the first and last names in the corresponding fields.
Type the employees hours for each day and click the Process button
 

After previewing the page, return to your text editor.

Besides the conversion functions, VBScript provides many other functions you can use in your scripts. Some of these functions are:

Language Element Description
Abs Function Returns the absolute value of a number.
Array Function Returns a Variant containing an array.
Asc Function Returns the ANSI character code corresponding to the first letter in a string.
Atn Function Returns the arctangent of a number.
CBool Function Returns an expression that has been converted to a Variant of subtype Boolean.
CByte Function Returns an expression that has been converted to a Variant of subtype Byte.
CCur Function Returns an expression that has been converted to a Variant of subtype Currency.
CDate Function Returns an expression that has been converted to a Variant of subtype Date.
CDbl Function Returns an expression that has been converted to a Variant of subtype Double.
Chr Function Returns the character associated with the specified ANSI character code.
CInt Function Returns an expression that has been converted to a Variant of subtype Integer.
CLng Function Returns an expression that has been converted to a Variant of subtype Long.
Cos Function Returns the cosine of an angle.
CreateObject Function Creates and returns a reference to an Automation object.
CSng Function Returns an expression that has been converted to a Variant of subtype Single.
CStr Function Returns an expression that has been converted to a Variant of subtype String.
Date Function Returns the current system date.
DateAdd Function Returns a date to which a specified time interval has been added.
DateDiff Function Returns the number of intervals between two dates.
DatePart Function Returns the specified part of a given date.
DateSerial Function Returns a Variant of subtype Date for a specified year, month, and day.
DateValue Function Returns a Variant of subtype Date.
Day Function Returns a whole number between 1 and 31, inclusive, representing the day of the month.
Eval Function Evaluates an expression and returns the result.
Exp Function Returns e (the base of natural logarithms) raised to a power.
Filter Function Returns a zero-based array containing subset of a string array based on a specified filter criteria.
Fix Function Returns the integer portion of a number.
FormatCurrency Function Returns an expression formatted as a currency value using the currency symbol defined in the system control panel.
FormatDateTime Function Returns an expression formatted as a date or time.
FormatNumber Function Returns an expression formatted as a number.
FormatPercent Function Returns an expression formatted as a percentage (multiplied by 100) with a trailing % character.
GetLocale Function Returns the current locale ID value.
GetObject Function Returns a reference to an Automation object from a file.
GetRef Function Returns a reference to a procedure that can be bound to an event.
Hex Function Returns a string representing the hexadecimal value of a number.
Hour Function Returns a whole number between 0 and 23, inclusive, representing the hour of the day.
InputBox Function Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box.
InStr Function Returns the position of the first occurrence of one string within another.
InStrRev Function Returns the position of an occurrence of one string within another, from the end of string.
Int Function Returns the integer portion of a number.
IsArray Function Returns a Boolean value indicating whether a variable is an array.
IsDate Function Returns a Boolean value indicating whether an expression can be converted to a date.
IsEmpty Function Returns a Boolean value indicating whether a variable has been initialized.
IsNull Function Returns a Boolean value that indicates whether an expression contains no valid data (Null).
IsNumeric Function Returns a Boolean value indicating whether an expression can be evaluated as a number.
IsObject Function Returns a Boolean value indicating whether an expression references a valid Automation object.
Join Function Returns a string created by joining a number of substrings contained in an array.
LBound Function Returns the smallest available subscript for the indicated dimension of an array.
LCase Function Returns a string that has been converted to lowercase.
Left Function Returns a specified number of characters from the left side of a string.
Len Function Returns the number of characters in a string or the number of bytes required to store a variable.
LoadPicture Function Returns a picture object. Available only on 32-bit platforms.
Log Function Returns the natural logarithm of a number.
LTrim Function Returns a copy of a string without leading spaces.
Mid Function Returns a specified number of characters from a string.
Minute Function Returns a whole number between 0 and 59, inclusive, representing the minute of the hour.
Month Function Returns a whole number between 1 and 12, inclusive, representing the month of the year.
MonthName Function Returns a string indicating the specified month.
MsgBox Function Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.
Now Function Returns the current date and time according to the setting of your computer's system date and time.
Oct Function Returns a string representing the octal value of a number.
Replace Function Returns a string in which a specified substring has been replaced with another substring a specified number of times.
RGB Function Returns a whole number representing an RGB color value.
Right Function Returns a specified number of characters from the right side of a string.
Rnd Function Returns a random number.
Round Function Returns a number rounded to a specified number of decimal places.
RTrim Function Returns a copy of a string without trailing spaces.
ScriptEngine Function Returns a string representing the scripting language in use.
ScriptEngineBuildVersion Function Returns the build version number of the scripting engine in use.
ScriptEngineMajorVersion Function Returns the major version number of the scripting engine in use.
ScriptEngineMinorVersion Function Returns the minor version number of the scripting engine in use.
Second Function Returns a whole number between 0 and 59, inclusive, representing the second of the minute.
SetLocale Function Sets the global locale and returns the previous locale.
Sgn Function Returns an integer indicating the sign of a number.
Sin Function Returns the sine of an angle.
Space Function Returns a string consisting of the specified number of spaces.
Split Function Returns a zero-based, one-dimensional array containing a specified number of substrings.
Sqr Function Returns the square root of a number.
StrComp Function Returns a value indicating the result of a string comparison.
String Function Returns a repeating character string of the length specified.
StrReverse Function Returns a string in which the character order of a specified string is reversed.
Tan Function Returns the tangent of an angle.
Time Function Returns a Variant of subtype Date indicating the current system time.
Timer Function Returns the number of seconds that have elapsed since 12:00 AM (midnight).
TimeSerial Function Returns a Variant of subtype Date containing the time for a specific hour, minute, and second.
TimeValue Function Returns a Variant of subtype Date containing the time.
Trim Function Returns a copy of a string without leading or trailing spaces.
TypeName Function Returns a string that provides Variant subtype information about a variable.
UBound Function Returns the largest available subscript for the indicated dimension of an array.
UCase Function Returns a string that has been converted to uppercase.
VarType Function Returns a value indicating the subtype of a variable.
Weekday Function Returns a whole number representing the day of the week.
WeekdayName Function Returns a string indicating the specified day of the week.
Year Function Returns a whole number representing the year.