Thread Rating:
  • 393 Vote(s) - 2.74 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Page 5: Application: Reading Our Score Data
06-20-2011, 01:20 PM, (This post was last modified: 06-23-2011, 04:26 PM by ashimo.)
#1
Page 5: Application: Reading Our Score Data
Application: Reading Our Score Data

We’ll read the data containing our scores, and then display it.

Create the 'Try 5-3' Project

Close the Try 5-2 project and then, from the IDE 'File' menu, select 'New Project'. In the 'New Project' dialog box, select “Applet Project” (1), input “Try5-3” (2), specify c:\Curl\lesson\Try5\03_score_file in the “Directory” field (3), set the API Version to 6.0 (4), and then click OK (5).



Inputting the Program

Copy the c:\Curl\Try5\03_score_file\score.txt file to the c:\Curl\lesson\Try5\03_score_file directory. Next, we’ll input the program. You can copy the program code below or use c:\Curl\Try5\03_score_file\start.curl and then paste it into the editor in the IDE.



Code:
{value
    let loc:Url = {url score.txt}
    let in:#TextInputStream
    let data-array:StringArray = {StringArray}
    let record-set:RecordSet = {RecordSet
                                   {RecordFields
                                       {RecordField name, domain = String},
                                       {RecordField age, domain = int},
                                       {RecordField score, domain = int}
                                   }
                               }
    
    {try
        set in = {read-open loc}
        {until in.end-of-stream? do
            {if-non-null line = {in.read-line} then
                {data-array.append {line.to-String}}
            }
        }
     catch e:IOException do
        {popup-message Error reading file}
        {output e.message}
     finally
        {if-non-null in then
            {in.close}
        }
    }
    
    {for data:String in data-array do
        let array:StringArray = {data.split split-chars = ,}
        {if array.size == 3 then
            {record-set.append
                {RecordData
                    name = array[0], age = {array[1].to-int}, score = {array[2].to-int}
                }
            }
        }
    }
    
    {RecordGrid
        record-source = record-set,
        width = 10cm,
        height = 3cm
    }
}

Save the File, and then Execute the Program

After inputting the code, save the file, and then execute the program. The following result will appear in your browser.



Messages In This Thread
Page 5: Application: Reading Our Score Data - by ashimo - 06-20-2011, 01:20 PM

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 6: Structure of a Program that Reads our Score Data ashimo 0 2,970 06-20-2011, 01:21 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
Forum Jump:


Users browsing this thread:
2 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('75')