06-20-2011, 01:21 PM,
(This post was last modified: 06-23-2011, 04:26 PM by ashimo.)
|
|||||
|
|||||
Page 6: Structure of a Program that Reads our Score Data
Structure of the program that reads our score data
In this example, the data that is read from the file is displayed using a RecordGrid. 1. Specifying the location of the file Code: let loc:Url = {url score.txt} Specify the location of the file. 2. Declaration of a TextInputStreams Code: let in:#TextInputStream To read data from the file, we have to declare TextInputStream. 3. Declaration of character string array used to save read-in data Code: let data-array:StringArray = {StringArray} Declare the character string array to be used for the data read from a file. 4. Declaration of RecordSet used to store data Code: let record-set:RecordSet = In this sample, the data obtained from a file is converted to a RecordSet, and then later displayed using RecordGrid. 5. Opening a file Code: set in = {read-open loc} Using read-open, we open the specified file as a TextInputStream. 6. Reading the data Code: {until in.end-of-stream? do The data is read, line-by-line, and then added to the character string array. 7. Closing the file Code: {if-non-null in then Regardless of whether the data read from the file is successful or not, the open file must be closed. 8. Data conversion Code: {for data:String in data-array do We have to convert the data that is stored in a StringArray to a RecordSet. Each line of data in the file corresponds to one record. Also, each field is delimited by a comma (,). So, using the String.split method and a comma (,) as the delimiter, we partition the data and then save it into an array. Using the data in that array, we create RecordData, and then add it to a RecordSet. 9. Displaying the layout Code: {RecordGrid We take the RecordSet that we created in (8) and then display it using a RecordGrid. Working with CSV Data The Curl language also provides a predefined API for reading and writing CSV (comma separated values) formatted files. Using CsvRecordSet, you can load data directly as a RecordSet for further manipulation and/or display. Please refer to the Curl documentation for more information |
|||||
« Next Oldest | Next Newest »
|
Possibly Related Threads... | |||||
Thread | Author | Replies | Views | Last Post | |
Page 8: Extra Practice | ashimo | 0 | 3,482 |
06-20-2011, 01:34 PM Last Post: ashimo |
|
Page 7: Summary | ashimo | 0 | 3,046 |
06-20-2011, 01:23 PM Last Post: ashimo |
|
Page 5: Application: Reading Our Score Data | ashimo | 0 | 2,775 |
06-20-2011, 01:20 PM Last Post: ashimo |
|
Page 4: Structure of a Program that Writes Data to a File | ashimo | 0 | 3,148 |
06-20-2011, 01:18 PM Last Post: ashimo |
|
Page 3: Basics 2: Writing a Control Value into a File | ashimo | 0 | 3,022 |
06-20-2011, 01:16 PM Last Post: ashimo |
|
Page 2: Structure of a Program that Reads Data from a File | ashimo | 0 | 3,039 |
06-20-2011, 01:13 PM Last Post: ashimo |
|
Page 1: Reading Our Score Data | ashimo | 0 | 3,171 |
06-20-2011, 01:12 PM Last Post: ashimo |
Users browsing this thread:
1 Guest(s)
1 Guest(s)