ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
TYPE Statement Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' This example use the PUT statement to store test scores in a random-access
' file. The TYPE statement is used to create a user-defined variable type.
 
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
 
 TYPE TestRecord                       ' Define record fields
    NameField  AS STRING * 20
    ScoreField AS SINGLE
 END TYPE
 
 DIM FileBuffer AS TestRecord
 DIM I AS LONG                         ' Open the test data file
 OPEN "TESTDAT.DAT" FOR RANDOM AS #1 LEN = LEN(FileBuffer)
 CLS                                   ' Clear the screen
 I = 0
 DO                                    ' Read pairs of names and
     I = I + 1                         ' scores from the console
     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
 KILL "TESTDAT.DAT"                    ' Remove file from disk