Create document

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 6.7.1 (Modified)


Create document (document{; type}) DocRef

ParameterTypeDescription
documentStringDocument name or
Full document pathname or
Empty string for standard file dialog box
typeStringMac OS file type (4-character string) or
Windows file extension (1- to 3-character string) or
TEXT (.TXT) document if omitted
Function resultDocRefDocument reference number

Description

The Create document command creates a new document and returns its document reference number.

Pass the name or full pathname of the new document in document. If document already exists on the disk, it is overwritten. However, if document is locked or already open, an error is generated.

If you pass an empty string in document, the Save As dialog box is displayed and you can then enter the name of the document you want to create. If you cancel the dialog, no document is created; Create document returns a null DocRef and sets the OK variable to 0.

If the document is correctly created and opened, Create document returns its document reference number and sets the OK variable to 1. The system variable Document is updated and returns the access path of the created document.

Whether or not you use the Save As dialog box, Create document creates a .TXT (Windows) or TEXT (Macintosh) document by default. If you want to create another type of document, pass the fileType parameter.

On Macintosh, you pass a file type. On Windows you pass a 1- to 3-character Windows file extension or Macintosh file type mapped through the MAP FILE TYPES mechanism. If you want to create a document without an extension, a document containing several extensions, or a document containing an extension with more than three characters, do not use the type parameters and pass the full name in document (see example2).

Once you have created and opened a document, you can write and read the document using the SEND PACKET and RECEIVE PACKET commands that you can combine with the Get document position and SET DOCUMENT POSITION commands in order to directly access any part of the document.

Do not forget to eventually call CLOSE DOCUMENT for the document.

Examples

1. The following example creates and opens a new document called Note, writes the string "Hello" into it, and closes the document:

   C_TIME(vhDoc) 
   vhDoc:=Create document ("Note")  ` Create new document called Note 
   If (OK=1) 
      SEND PACKET(vhDoc; "Hello")  ` Write one word in the document 
      CLOSE DOCUMENT(vhDoc)  ` Close the document 
   End if

2. The following example creates documents with non-standard extensions under Windows:

   $vtMyDoc:=Create document("Doc.ext1.ext2") `Several extensions
   $vtMyDoc:=Create document("Doc.shtml") `Long extension
   $vtMyDoc:=Create document("Doc.") `No extension (the period "." is mandatory)

System Variables or Sets

If the document has been created correctly, the system variable OK is set to 1 and the system variable Document contains either the name or the full pathname and the name of document, depending on the value passed in document (if you passed a file name, Document contains this name; if you passed a full pathname, Document contains this full pathname).

See Also

Append document, Open document.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next