CircuitGizmos

Electronic Products for Creative Minds

  • Home
  • Gizmo Store/Products
  • Documentation/Datasheets
  • Projects/Libraries
  • GizmoBlog
  • Services/Contact
    • Design
    • Contact Gizmo!
  • Your Gizmo Cart
    • Your Account
You are here: Home / GizmoBlog / MMBasic Language / File System / OPEN (file)

OPEN (file)

OPEN fname$ FOR mode AS [#]fnbr

Opens a file for reading or writing.

‘fname’ is the file name (8 chars max) with an optional extension (3 chars max) separated by a dot (.). It can be prefixed with a directory path.

For example:


OPEN "B:\DIR1\DIR2\FILE.EXT" FOR INPUT AS #1


‘mode’ is INPUT or OUTPUT or APPEND.

INPUT will open the file for reading and throw an error if the file does not exist.

OUTPUT will open the file for writing and will automatically overwrite any existing file with the same name.

APPEND will also open the file for writing but it will not overwrite an existing file; instead any writes will be appended to the end of the file. If there is no existing file the APPEND mode will act the same as the OUTPUT mode (i.e. the file is created then opened for writing).

Note: APPEND is not supported on the flash file system (drive A:).
‘fnbr’ is the file number (1 to 10). The # is optional. Up to 10 files can be open simultaneously. The INPUT, LINE INPUT, PRINT, WRITE and CLOSE commands as well as the EOF() and

INPUT$() functions all use ‘fnbr’ to identify the file being operated on.

See also OPTION ERROR and MM.ERRNO for error handling.

The length of the path plus the file name (including punctuation) must be less than 127 characters.

The following code will try to open a file. If it is not there, an error occurs.


1
2
<span style="color: #008000;">' Stop error from halting program</span><span style="color: #008000;">
OPTION ERROR CONTINUE</span>

1
<span style="color: #008000;">FileStatus = 1</span>

1
<span style="color: #008000;">OPEN "test.txt" FOR INPUT AS #1</span>

1
2
<span style="color: #008000;">  ' Check error condition</span>
<span style="color: #008000;">  IF MM.ERRNO = 6 THEN FileStatus = 0</span>

1
<span style="color: #008000;">OPTION ERROR ABORT</span>

1
2
<span style="color: #008000;">' If file opened without error...</span>
<span style="color: #008000;">IF FileStatus = 1 THEN</span>

1
<span style="color: #008000;">  ' Process opened file here</span>

1
<span style="color: #008000;">ENDIF</span>


See also:
CLOSE
EOF
INPUT#
INPUT$
LINE INPUT
PRINT
SEEK
WRITE

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

A Ton of Documentation

Open all | Close all

Projects made by Gizmo, Friends, and Members

open all | close all

Recent GizmoBlog Musings

  • Altair 8800 using a ColorMax!
  • Re-energizing the ColorMax, Pt. 3

Visit us!

  • Facebook

Electronic Products for Creative Minds

CircuitGizmos is your source for electronic products that help you create your embedded projects. Here at CircuitGizmos.com you will find a friendly store filled with creative products and all of the documentation that you need to use these gizmos.

We create devices that we believe make electronics fun, but we also know that our products are used for professional designs. For decades we have designed products for commercial, military, and medical industries. Our gizmos here are great for engineers and hobbyists alike.

Copyright © 2008+ CircuitGizmos, L.L.C. All rights reserved

Image already added

Recently Viewed Products

Copyright © 2021 · Generate Pro Theme on Genesis Framework · WordPress · Log in