* *
*
* * News
 • Daily news
 • Archived news

Columns
 • WildCard
 • Qbasic Articles
 • QB Comic!

Learning center
 • QB Books
 • Qbasic Lessons!
 • Qbasic FAQ
 • Newbies Section
 • Qbasic Tutorials

* *
*
*
*
*  
.PUT (File I/O) Statement Programming Example.

  QuickSCREEN      Details     Example      Contents      Index
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
PUT (File I/O) Statement Programming Example
This example reads names and test scores from the console and stores them
in a random-access file.
 
' Read a name and a test score from the console.
' Store each name and score as a record in a
' random-access file.
 
' Define record fields.
TYPE TestRecord
   NameField  AS STRING * 20
   ScoreField AS SINGLE
END TYPE
 
' Open the test data file.
DIM FileBuffer AS TestRecord
OPEN "TESTDAT.DAT" FOR RANDOM AS #1 LEN = LEN(FileBuffer)
 
' Read pairs of names and scores from the console.
 
CLS    ' Clear screen
I = 0
DO
   I = I + 1
   INPUT "Name ? ", FileBuffer.NameField
   INPUT "Score? ", FileBuffer.ScoreField
   INPUT "-->More (y/n)? ", Resp$
   PUT #1, I, FileBuffer
LOOP UNTIL UCASE$(MID$(Resp$, 1, 1)) = "N"
 
PRINT I; " records written."
 
CLOSE #1
* * ** * * * *