File Input and Output - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

File Input and Output

Description:

must be written and read in consecutive order ... Concludes input/output (I/O) to a file opened using the Open statement. Syntax: ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 12
Provided by: scie248
Learn more at: http://www.cs.uwyo.edu
Category:

less

Transcript and Presenter's Notes

Title: File Input and Output


1
File Input and Output
  • Sequential Access Files

2
Format Function
  • Syntax
  • Format(expression, format)
  • Example
  • lblNumber.Caption You owe Format(dblSum,
    "Currency")
  • or
  • picOutput.Print Format(dblAnswer, Fixed)

3
Built-in Numeric Formats
  • General Number
  • Currency
  • Fixed
  • Standard
  • Percent
  • Scientific

4
User-defined Number Formats
  • 0 display digit or zero
  • display digit or nothing
  • . decimal placeholder
  • , thousands separator
  • percent
  • - display the literal character
  • lblTaxes.Caption Format(dblDollars,,0.00")

5
Sequential Access Files
  • each record appears on a separate line
  • fields are separated by commas
  • "Jackets",45
  • "Hats",15
  • must be written and read in consecutive order
  • files can be created with NotePad and stored as
    .txt files

6
File Access Statements
  • Open statement to open the file
  • Input statement to read from the file
  • Write or Print statement to write to the file
  • Close statement to close the file

7
Open Statement
  • Enables input/output (I/O) to a file.
  • Open pathname For mode As filenumber
  • Open a\Data.txt" For Input As 1

8
Input Statement
  • Reads data from an open sequential file and
    assigns the data to variables.
  • Syntax
  • Input filenumber, varlist
  • Example
  • Input 1, strItem, intOrder

9
Write Statement
  • Writes data to an open sequential file.
  • Syntax
  • Write filenumber, outputlist
  • Example
  • Write 1, strItem, intOrder

10
Print Statement
  • Writes display-formatted data to an open
    sequential file.
  • Print filenumber, outputlist
  • Open a\data.txt" For Output As 1
  • Print 1, "This is a test"
  • Print 1, Spc(5) "5 leading spaces "
  • Print 1, Hello Tab(10) World!

11
Close Statement
  • Concludes input/output (I/O) to a file opened
    using the Open statement.
  • Syntax
  • Close filenumberlist
  • Example
  • Close 1
  • If you omit filenumberlist, all active files
    opened by the Open statement are closed.
Write a Comment
User Comments (0)
About PowerShow.com