Copyright 2008 Shoptalk Systems

OPEN filePath$ FOR mode AS #handle {LEN = n}


    filePath$ - This string expression specifies the path and name of a file.  ie.  "c:\myfolder\myfile.txt"

    mode - The mode parameter will be one of: INPUT, OUTPUT, APPEND, RANDOM or BINARY

    #handle - This is the variable name to which the open file will be assigned.

    LEN - This parameter specifies how many characters long each record is when mode is RANDOM.


  open "foxjump.txt" for output as #writeIt
  print #writeIt, "The quick brown fox jumped over the lazy dog."
  close #writeIt
  open "foxjump.txt" for input as #readIt
  input #readIt, text$
  close #readIt
  print text$

Note: Any device that is opened during the normal operation of the program must be closed before program execution is finished. See CLOSE

INPUT - A file opened for reading using INPUT is usually a plain text file. The file must already exist or a runtime error will occur.  Read the file using the INPUT statement or the INPUT$() or INPUTTO$() functions.

OUTPUT - Opening a file using OUTPUT will create a new file if it doesn't exist, and it will delete the file of the same name and create a new empty file if the file already exists.  Use the PRINT statement to write to the file.

APPEND - Use APPEND to write new data to the end of an already existing file.  Again, use the PRINT statement.

RANDOM - This mode is for reading and writing files using records.  Use the LEN parameter to specify the number of characters in a record, like so:

  open "mydata.dat" for random as #dbase len = 230

In this example the combined fields (see FIELD) in a record must add up to 230 characters.

BINARY - This mode is designed to faithfully read and write characters exactly as they are written.