Customer Gas Usage
Customer Gas Usage Records Layout
Field 1 |
Field 2 |
Field 3 |
Field 4 |
Customer Number |
Customer Name |
Address |
Gas Used |
Using the Customer Gas Usage Records
- The records are made available to your programs with this function:
| // The open function
openCustomerGasUsageRecords();
|
* The function returns the records so you need to store them in a variable:
| // Record set variable
let records;
records = openCustomerGasUsageRecords();
|
* After the openCustomerGasUsageRecords() 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.getCustomerNumber();
records.getCustomerName();
records.getCustomerAddress();
records.getCustomerGasUsage();
|
-
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
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 | /*
This is an example of using the
Customer Gas Usage Record Set
*/
function customerGasUsageDemo() {
"use strict";
// Variable Declarations
let customerNumber;
let customerName;
let address;
let gasUsed;
let outputTable;
let outputRows;
let records;
// Get the HTML output table so we can add rows
outputTable = document.getElementById("outputTable");
// build table header
outputRows = "<tr><th>Customer Number</th>"
+ "<th>Customer<br />Name</th>"
+ "<th>Address</th>"
+ "<th>Gas<br />Used</th></tr>";
// Open the Customer Gas Usage Records and make them
// available to the script
records = openCustomerGasUsageRecords();
// Test to see if there is a next record and then output it
while (records.readNextRecord()) {
customerNumber = records.getCustomerNumber();
customerName = records.getCustomerName();
address = records.getCustomerAddress();
gasUsed = records.getCustomerGasUsage();
outputRows += "<tr><td>"
+ customerNumber
+ "</td><td>"
+ customerName
+ "</td><td>"
+ address
+ "</td><td>"
+ gasUsed.toFixed(1) + "</td></tr>";
}
// output table rows
outputTable.innerHTML = outputRows;
}
|
Customer Gas Record Data