Thread Rating:
  • 471 Vote(s) - 2.77 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Page 3: Basics 2: Writing a Control Value into a File
06-20-2011, 01:16 PM, (This post was last modified: 06-23-2011, 04:24 PM by ashimo.)
#1
Page 3: Basics 2: Writing a Control Value into a File
Basics 2: Writing a Control Value into a File

Create the 'Try 5-2' Project

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


Inputting the Program

Next, we’ll input the program. You can copy the program code below or use c:\Curl\Try5\02_write_file\start.curl and then paste it into the editor in the IDE.

Code:
{value
    let out:#TextOutputStream
    let v:VBox = {VBox spacing = 3.5pt, margin = 10pt, halign = right}    
    let title-array:StringArray = {StringArray
                                      Name: , Company: , Address: ,
                                      Phone: , Email:
                                  }
    let field-array:{Array-of TextField} = {{Array-of TextField}}
    
    {for i:int = 0 below 5 do
        {field-array.append {TextField width = 5cm}}
        {v.add
            {HBox
                title-array+,
                field-array+
            }
        }
    }
    
    {v.add
        {CommandButton
            label = Save,
            {on Action do
                {if-non-null loc = {choose-file style = save-as} then
                    {try
                        set out = {write-open
                                      error-if-exists? = true,
                                      loc
                                  }
                        {for tx:TextField in field-array do
                            {out.write-one-string tx.value & "\r\n}
                        }
                     catch e:ExistingFileException do
                        {popup-message That file already exists.}
                        {output e.message}
                     catch e:IOException do
                        {popup-message Error writing to file."}
                        {output e.message}
                     finally
                        {if-non-null out then
                            {out.close}
                        }
                    }
                 else
                }
            }
        }
    }
    v
}

Save the File, and then Execute the Program

After inputting the code, save the file, and then execute the program. The execution results are displayed by the browser ((1)). Input values into a text fields, and then click the \[Save\] button ((2)). The “Save as” dialog box is displayed. This lets us create a new text file and then save the data to a convenient location. If we check the contents of the text file, then we should find that it contains the data that we entered.


Messages In This Thread
Page 3: Basics 2: Writing a Control Value into a File - by ashimo - 06-20-2011, 01:16 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 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 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('73')