Currently Being Moderated

Try 5: Page 5

VERSION 1

Created on: Mar 5, 2008 11:43 AM by Curl Education - Last Modified:  Jul 3, 2008 3:34 PM by Curl Education

!../../wiki/easy-ide-book/common/images/prev_page.gif! !../../wiki/easy-ide-book/common/images/toc.gif! !../../wiki/easy-ide-book/common/images/next_page.gif!

 

 

 

<font color="navy">Application: Reading Our Score Data</font>

 

 

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

 

<font color="black">Create the 'Try 5-3' Project</font>

 

 

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).

 

 

<font color="black">Inputting the Program</font>

 

 

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.

 

 

{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
    }
}

 

 

<font color="black">Save the File, and then Execute the Program</font>

 

 

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

 

 

!../../wiki/easy-ide-book/common/images/next_page.gif!

Average User Rating
(0 ratings)




There are no comments on this document

More Like This

  • Retrieving data ...