Warning: This function is maintained for backward compatibility. It is strongly recommended to use the
File data type, its properties, and methods instead of this function.
Opens a text file for its processing. It is the first function to be called to begin reading a text file.
DFROpen(FileName [ , length [ , fdel [ , sdel [ , encoding ] ] ] ] )
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 (deprecated)
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 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”. The default value is "," (comma).
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 appearing in the texts. Thedefault value is “ (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”.
Type Returned:
Numeric
Objects: Procedure, Transaction, Web Panel, Data Provider
Generators: .NET, .NET Framework, Java, Ruby (up to GeneXus X Evolution 3)
This function may return some of the following values:
Value |
Result |
Description |
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 DFRClose 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 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. |
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
&Text = "Could not open file"
EndIf
Delimited ASCII files functions