Xbasic

FILE.CREATE Function

Syntax

file_pointer as P = FILE.Create(C Filename,N file_open_mode)

Arguments

FilenameCharacter

The file name, including drive and path.

file_open_modeNumeric

The Open Mode system variables are:

Variable
Function
FILE_RO_EXCLUSIVE

Read Only (Exclusive)

FILE_RW_EXCLUSIVE

Read or Write (Exclusive)

FILE_RO_SHARED

Read Only (Shared)

FILE_RW_SHARED

Read or Write (Shared)

Returns

file_pointerPointer

Returns a file object pointer.

Description

Create a new file.

Discussion

The FILE.CREATE() method creates and opens a new file, returning a file object pointer reference to the file.

When you delete the file object pointer, Alpha Anywhere closes the file.

Ask user to type a new filename.

filename = ui_get_file("Create a file","Text Files (*.txt)", "c:\a5\defaults.txt","N")
if (filename = "") then
    end
end if

Example 

Create the file.

file_pointer = file.create(filename, FILE_RW_EXCLUSIVE)

Write first line of data to the file.

for i = 1 TO 5
    file_pointer.write("A5_" + ltrim( str(i) ) )
next i
'New line
file_pointer.write_line("")
'Write another line of data
for i = 1 TO 5
    file_pointer.write("VAR" + ltrim( str(i) ) )
next i
file_pointer.flush()
file_pointer.close()

See Also