Opens a text file for its processing.  It is the first function to be called to begin reading a text file.

Syntax

DFROpen(FileName [ , length [ ,  fdel [ ,  sdel [ ,  encoding ] ] ] ] )

Type Returned:
Numeric

Where:

FileName

It can be an attribute, variable or constant of the char type.  Its value will be considered as the file name to be processed.  It may contain directory specifications or not.  If it doesn’t, it will be searched in the current directory.

length

It can be an attribute, variable or constant of the numeric type, optional, which indicates the maximum size, in number of characters, of the record to be read.  See that the delimited ASCII files have records (lines) of variable length.  If it is specified, the value should correspond to the maximum quantity of characters that a line may have.  The default value is 1024.

fdel

It can be an attribute, variable or constant of the character type, optional, which indicates the delimiting character among fields.  If you wish to specify the tab character as separator, the value of this parameter must be the string “\t”.

sdel

It can be an attribute, variable or constant of the character type, optional,  which indicates  the delimiting character of the string fields.  Only the first character of the parameter value is considered.  Its value may be any character not apperaing in the texts.  Its default value is the “ (quotation mark).

encoding

It can be an attribute, variable or constant of the character type, optional, which indicates the encoding to be used to read the file. If you specify this parameter, it means that the length used in the function DFRGTxt means “number of bytes”.

Values

This function may return some of the following values:

 0: Successful operation. The file has been opened.
-1: Wrong sequence. It occurs when this function is called more than once without previously calling the dfwclose function. If the trace is activated you will see the ADF0005 message indicating this error.
-2: Opening error. It occurs when the file identified as <filename> could not be opened.  The cause may be clearly identified by enabling the trace and looking for the message with ADF0001 code. It is most common that the file does not exist.
-8: Not enough memory.  It occurs when it isn’t possible to reserve a buffer of <length> bytes.  If the trace is activated, you will see the ADF0007 message indicating this error.

Example

For this example, the parameter field separator is not required.

&Text = ""
&i = dfropen( "Test.txt",1024,,"") 
If &I = 0
    Do while dfrnext( ) = 0
       &i = dfrgtxt(&Linetxt) // The length of the line is given by the size of the variable.
       &Text = &Text + Newline() + &Linetxt
    EndDo
    &i = dfrclose( )
else
    &Texto = "Could not open file"
EndIf

Scope

Objects: Procedures, Transactions, Web Panels
Languages: .NET, Java, Ruby (up to GeneXus X Evolution 3)

See Also

Delimited ASCII files functions