FutureBasic Logo

<<    Index    >> FutureBasic 5

def open   statement

def open [=] typeCreatorPascalString

Use this statement to specify the file type and/or creator signature to be assigned to files which are subsequently opened for output by the Open statement. typeCreatorPascalString should be a string expression whose length is either 4 or 8 characters. The first 4 characters will be used as the file type for newly opened files; the second group of 4 characters (if any) will be used as the creator signature for newly opened files. The specified typeCreatorPascalString remains in effect until another Def Open statement is executed.

A Macintosh file may have 4-character file type and a 4-character creator signature (See Note 2). The file type is usually used to signify the general format of the file's contents. If you're creating a file which is to be opened by another application, you should use a file type which the other application recognizes. Otherwise, you can make up a custom file type for your program's private use. By default (i.e., if your program hasn't yet executed a Def Open statement), FutureBasic assigns the file type "????" to files opened for output.

A file's creator signature usually signifies which application created the file. The Finder uses the file's creator signature to determine such things as: which application to launch when the user double-clicks the file's icon. The Finder uses the file's creator signature, in combination with the file's type, to determine the icon to display for the file. By default, if your program hasn't yet executed a Def Open statement with an 8-character typeCreatorPascalString parameter, FutureBasic assigns the creator signature "????" to files opened for output.

Def Open "ttrottxt"
Open "O", #1, "test file",@parentFolderRef // an FSRef cannot be created for a non-existent file, so a filename is supplied
Print #1, "This is a test file"
Close #1

The program above creates a file whose type is "ttro" and whose creator signature is "ttxt". The Finder recognizes such a file as a SimpleText "read-only" text file. The file will appear with an appropriate icon, and the Finder will launch SimpleText when the user double-clicks the file's icon.

(1) Def Open only applies to files which are opened with the "O" option. It does not affect the type nor creator signature of files which are opened for input only ("I") or for random access ("R").
(2) Apple has recommended use of Uniform Type Identifiers to replace Type/Creator. See Apple's "Introduction to Uniform Type Identifiers" for more information.

See Also:
files$; open