Zip Code Study
Zip Code Study Records Layout
Field 1 |
Field 2 |
Field 3 |
Field 4 |
First Name |
Last Name |
Status |
Zip Code |
Using the Customer Gas Usage Records
- The records are made available to your programs with this function:
| // The open function
openZipCodeStudyRecordSet();
|
* The function returns the records so you need to store them in a variable:
| // Record set variable
let records;
records = openZipCodeStudyRecordSet();
|
* After the openZipCodeStudyRecordSet() function has been run you have access to the first record's data. You will retrieve each part of one record with a different function. Here are the functions:
| // Field functions
records.getSampleFirstName();
records.getSampleLastName();
records.getSampleStatus();
records.getSampleZipCode();
|
-
Notice that you need to have "records." in front of each of the functions.
-
When you want to read the next record you use the following function. It will make the next record available and you then use the above functions to retrieve the data. This function returns true
if there was a next record and false
if the end of the record set has been reached.
| // Read the next record or stop the loop
studentRecords.readNextRecord();
|
Example Usage
Notice the if
statement in the while
loop. This stops the loop after the first 25 records have been processed. This is an excellent way to test a sub-set of data!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 | /*
This is an example of using the
Zip Code Study Record Set
*/
function zipCodeStudyRecords() {
"use strict";
// Variable Declarations
let firstName;
let lastName;
let status;
let zipCode;
let outputTable;
let records;
let count;
let outputRows;
count = 0;
// Get the HTML output table so we can add rows
outputTable = document.getElementById("outputTable");
// build table header
outputRows = "<tr><th>First<br />Name</th>"
+ "<th>Last<br />Name</th>"
+ "<th>Status</th>"
+ "<th>Zip Code</th></tr>";
// Open the Zip Code Study Records and make them
// available to the script
records = openZipCodeStudyRecordSet();
while (records.readNextRecord()) {
// This IF only in place for this particular example program
// Remove the IF to work with the entire file
if (count >= 25) {
break;
}
firstName = records.getSampleFirstName();
lastName = records.getSampleLastName();
status = records.getSampleStatus();
zipCode = records.getSampleZipCode();
outputRows += "<tr><td>" + firstName + "</td>"
+ "<td>" + lastName + "</td><td>" + status
+ "</td><td>" + zipCode + "</td></tr>";
count += 1;
}
// Output table rows
outputTable.innerHTML = outputRows;
}
|
Zip Code Study Record Data