![]() Capt. Horatio T.P. Webb | the names of things | |
Data Types
HTML Object References
Array Declarations
|
VBSCRIPT VBscript is a "loosely typed" language. The definition of data items (i.e., variables) does NOT have to be done before using the variable in the body of the program. In contrast to languages like C and COBOL where data items have to be defined (declared) before they are used, VBScript allows you to use variables without having to define them first. The "data type' of the variable is determined by the context of its use. The choice of a data name is limited to names that do not exceed 255 characters. They should NOT be any VBscript reserve word or function (like loop, for, while, dim, sqr, log, etc.). They should begin with a letter (A-Z or a-z) and may contain the underscore( _ ) character. Data items are created in VBScript by their usage. All that is required is to assign a value to the name for it to be created (i.e., the data item must appear on the lefty-hand side of the assignment operator (=) ). For example: fred=1
all created variables named fred. These data names may be used to store a variety of different data types. The data types supported by VBScript are:
|
JAVASCRIPT Javascript is also a "loosely typed" language. The definition of data items (i.e., variables) does NOT have to be done before using the variable in the body of the program. The "data type' of the variable is determined by the context of its use. Variable names must begin with a letter or underscore (i.e, a thru Z, a thru z or _). Following the first character they can contain any letter, number or the underscore. Names cannot contain any punctuation character (e.g., , ( ) ; ' " $ %, etc.) and cannot be any javascript reserved words (e.g., for, Array, new, true, false, if, etc.).
| |||||||||
| Data types are defined by their context -- not specific declaractions (i.e., when making a variable assignment, VBScript and Javascript both choose the most appropriate data type for the given values. | ||||||||||
|
In addition to data items created by the program, there are objects that are used on the HTML page (e.g., radio buttons, cjheck boxes, etc.) that may be referenced by the VBScript code. These "intrinsic" (i.e., built in) HTML objects cannot be referenced by the use of the name= value in the HTML definition. They must be located in their context of the HTML code that is currently in the window. To reference any HTML object in the VBScript code, you can first establish a name for the object by using the SET command. The format is: set name_of_object = object hierarchy In javascript the same definition is applied by using: var name_of_object = object hierarchy; the object hierarchy is defined by the location of the object relative to the current window's contents. The entire browser window is called window. The window contains an HTML document named document, the document may contain one or more forms and the form may contain one or more intrinsic HTML objects (elements). the general format is:
Note that the form (name or number) and the element (name or number) can be used interchangeably. For example, suppose the following HTML page is to be referenced by VBScript code:
<html><body> <form name="formone"> <input type="text" name="T1"><br> <input type="text" name="T2"><br> <input type="text" name="T3"><br> </form> <form name="formtwo"> <input type="text" name="T4"><br> <input type="text" name="T5"><br> <input type="text" name="T6"><br> </form> </body><html> Then the six items' values can be referenced as:
| ||||||||||
|
VBSCRIPT ARRAYS
Arrays can be called vectors, lists or tables. They are used to store multiple items with the same data name -- but refer to the items by their number (where they appear in the list) rather than by name (i.e., where they appear in the array). Arrays come in two forms: (1) static and (2) dynamic.
To test the current size of the array you can use the Ubound function. The format is: size_of_array = UBound ( name_of_the_array) This will return the current array size. Note that thisis the maximum allowable value of a subscript -- NOT the count of array elements. You can also erase the array from memory by using the Erase command. The format is: Erase name_of_the_array Multi-Dimensional arrays can also be specified. For two-dimensional arrays (called matrices or tables -- as opposed to vectors and lists in the one dimensional case), you must specify the number of rows and the number of columns the array is to contain. Usage is: DIM name_of_the_array ( Number_of_rows - 1 , number_of_columns -1 ) for example an array named fred with 3 rows and 5 columns would be defined by: DIM fred(2,4) You may also specify three dimensional arrays using: DIM name_of_the_array ( Number_of_rows - 1 , number_of_columns - 1 , number_of_planes - 1 ) In this three dimensional case the third subscript refers to planes. For example: DIM fred(2,4,5) creates an array with three rows, five columns and six planes. |
JAVASCRIPT ARRAYS
Javascript arrays are defined in one of five ways: 1. var name_of_the_array= new Array(); 2. var name_of_the_array= new Array(size_of_array); 3. var name_of_the_array = []; 4. var name_of_the_array= new Array(element_value0,element_value1,element_value2,...element_valuen); 5. var name_of_the_array= [element_value0,element_value1,element_value2,...element_valuen]; Note that items (4) and (5) above allow you to define AND initialize the array in a single statement.
rather than the parentheses in vbscript (e.g., x(i) ). The elements of the array are numbered starting at zero. If the size option is used, then the last element of the array is size-1. If the elements are specifed (as in version 3), the number of elements is n+1 (i.e., 0,1,2,...,n). Elements in the array are referenced by an integer subscript such as: name_of_array[subscript] The number of elements in the array may be accessed by: name_of_array.length Array methods and functions:
Two dimensional arrays are created in Javascript by first creating an array and then making each element of the array a new array. the general form for an array with n rows and m columns would be:
var array_name = new Array (n-1); A reference to any row/column element is then: array_name[row_index][column_index] One can do this more quickly in the following loop:
var array_name = new Array (n-1)
Note: Javascript uses square bracket pairs for each subscript -- e.g., x[i][j] Vbscript uses single parentheses separating the subscripts by commas -- e.g., x(i,j) | |||||||||