A variable is an amount of memory space reserved to store part of the data used in your code. To use such a memory space, you must first let the browser know that you would need it. For the browser to reserve such a
memory space for you, and to use it eventually, you must give it a name. The memory space that is reserved will be used to receive some values from your application and to make such values available when your code needs
them. The contents of this reserved memory space can change or vary
regularly. For example, if you create a web page that acts as an employment application and include a text box for the first name, the content of the
first name text box will be different depending on each visitor. The memory space that stores the first name of the visitors will vary from one visitor to another. For this reason, it is called a variable.
The name of the variable:
- must start with a letter or an underscore character
- after the first character, can contain letters, digits, and underscores
- cannot contain empty space
When naming your variables, you should be a little explicit. A name such
as d intended to designate a date hired is difficult to figure out. On the other hand, if you plan to use a variable that represents a customer’s address, you can just call the
variable address.
For our lessons, sometimes we will start the names of
variables in uppercase. Instead of address, we may use Address; instead of
customers, we may use Customers. If the name is a combination of words,
such as firstname, we may start the first letter of each name in
uppercase. For example, instead of studentname, we may use StudentName;
instead of dateofbirth, we may use DateOfBirth. Various programmers use
different naming conventions. For example, some programmers use the
underscore to append two names of a variable. You are free to adopt which
ever convention suits you.
Practical Learning: Introducing Variables
|
|
- Start Notepad or your text editor
- In the empty file, type the following:
<html>
<head>
<title>VBScript Lessons</title>
</head>
<body>
<h1>Employee Payroll</h1>
<form name="frmPayroll">
<table border="0" width="504">
<tr>
<td width="144">First Name:</td>
<td width="101" colspan="2"><input type="text" name="txtFirstName" size="10"></td>
<td width="239" colspan="5"></td>
</tr>
<tr>
<td width="144">Last Name:</td>
<td width="101" colspan="2"><input type="text" name="txtLastName" size="10"></td>
<td width="239" colspan="5"></td>
</tr>
<tr>
<td width="144">Days:</td>
<td width="49">Mon</td>
<td width="46">Tues</td>
<td width="43">Web</td>
<td width="43">Thurs</td>
<td width="43">Fri</td>
<td width="43">Sat</td>
<td width="43">Sun</td>
</tr>
<tr>
<td width="144">Hours:</td>
<td width="49"><input type="text" name="txtMonday" size="5" value="0.00"></td>
<td width="46"><input type="text" name="txtTuesday" size="5" value="0.00"></td>
<td width="43"><input type="text" name="txtWednesday" size="5" value="0.00"></td>
<td width="43"><input type="text" name="txtThursday" size="5" value="0.00"></td>
<td width="43"><input type="text" name="txtFriday" size="5" value="0.00"></td>
<td width="43"><input type="text" name="txtSaturday" size="5" value="0.00"></td>
<td width="43"><input type="text" name="txtSunday" size="5" value="0.00"></td>
</tr>
<tr>
<td width="144">Hourly Salary:</td>
<td width="101" colspan="2">
<input type="text" name="txtHourlySalary" size="13" value="6.50"></td>
<td width="239" colspan="5"></td>
</tr>
<tr>
<td width="144">Weekly Hours:</td>
<td width="101" colspan="2">
<input type="text" name="txtWeeklyHours" size="13" value="0.00"></td>
<td width="239" colspan="5">
<input type="reset" value="ClearAll" name="btnClearAll"></td>
</tr>
<tr>
<td width="144">Weekly Salary:</td>
<td width="101" colspan="2">
<input type="text" name="txtWeeklySalary" size="10" value="0.00"></td>
<td width="239" colspan="5">
<input type="submit" value="Calculate" name="btnCalculate"></td>
</tr>
</table>
</form>
</body>
</html>
|
- Save the file as payroll1.htm in your VBScript Lessons
folder
- Preview the file in the browser
- Return to your text editor
|
|