PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Managing the errors
  • Position in the file
  • Managing the ANSI/UNICODE format
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Reads a line in an external file.
Windows Mobile The character string read is in UNICODE format, regardless of the format of the external file.
PHP In this version, you only have the ability to read a line in an external file in ANSI format.
Versions 15 and later
Android This function is now available for the Android applications.
New in version 15
Android This function is now available for the Android applications.
Android This function is now available for the Android applications.
Versions 16 and later
Universal Windows 10 App This function is now available for the Windows Phone applications.
New in version 16
Universal Windows 10 App This function is now available for the Windows Phone applications.
Universal Windows 10 App This function is now available for the Windows Phone applications.
Versions 17 and later
iPhone/iPad This function is now available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This function is now available for the iPhone/iPad applications.
iPhone/iPad This function is now available for the iPhone/iPad applications.
Versions 18 and later
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
New in version 18
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Versions 21 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
WINDEVWEBDEV - Server codeReports and QueriesJavaPHPAjaxUser code (UMC)
// Open an external file
FileID = fOpen("C:\MyDirectories\File.txt", foReadWrite)
IF FileID <> -1 THEN
// Read a line in this file
ResRead = fReadLine(FileID)
...
END
Windows Mobile
// Open an external file
FileID = fOpen("\MyDirectories\File.txt", foReadWrite)
IF FileID <> -1 THEN
// Read a line in this file
ResRead = fReadLine(FileID)
...
END
Syntax
<Result> = fReadLine(<File Identifier> [, <Separator>])
<Result>: Character string or UNICODE character string
  • Line read in an external file.
  • EOT constant if the end of file has been reached.
  • Empty string ("") if an error occurred. In this case, the ErrorOccurred variable is set to True.
Note: A line ends with a CR character (Carriage Return).
PHP This parameter must be a character string.
<File Identifier>: Integer
Identifier of the file to use, defined by fOpen or fCreate.
PHP This parameter must be a variant.
<Separator>: Character string (with or without quotes)
Versions 17 and later
Separator used between the lines. The default separator is the Carriage Return (CR).
AndroidAndroid Widget JavaPHP This parameter is not available. The separator used is the Carriage return (CR).
New in version 17
Separator used between the lines. The default separator is the Carriage Return (CR).
AndroidAndroid Widget JavaPHP This parameter is not available. The separator used is the Carriage return (CR).
Separator used between the lines. The default separator is the Carriage Return (CR).
AndroidAndroid Widget JavaPHP This parameter is not available. The separator used is the Carriage return (CR).
Remarks

Managing the errors

fReadLine generates an error in the following cases:
  • the file is not opened,
  • the file is not accessible in read mode,
  • the file is locked by another computer or by another application. fUnlock is used to unlock an external file.

Position in the file

When opening a file, the current position corresponds to:
  • the first byte of the file (by default),
  • the last byte of the file is the file is opened in "addition" mode (foAdd constant).
This position can be modified by fSeek.
fReadLine reads the specified elements from the current position. Once fReadLine has been run, the current position corresponds to the last byte read. fReadLine returns the EOT constant if the end of file has been reached.
WINDEVWEBDEV - Server codeReports and QueriesWindows MobileAjaxUser code (UMC)

Managing the ANSI/UNICODE format

fReadLine is used to read:
  • a Unicode string into a Unicode file.
  • an Ansi string into an Ansi file.
The file was created or opened by fCreate/fOpen while specifying the file type.
Depending on the format of the external file used, some conversions are required once a character string was read in an external file:
Current computer
External file
in ANSI format
(fOpen or fCreate associated with the foAnsi constant)
External file
in UNICODE format
(fOpen or fCreate associated with the foUnicode constant)
fReadLinePC running WindowsRead operation in ANSI format
Conversion to UNICODE possible with AnsiToUnicode
Pocket PCRead operation in UNICODE format
Conversion to ANSI possible with UnicodeToAnsi
Note: If the result of fReadLine on an ANSI file is assigned to a UNICODE string (and conversely), the conversion will be implicitly performed.
See Managing the UNICODE format for more details
Related Examples:
Handling text files Unit examples (WINDEV): Handling text files
[ + ] Handling "text" files with WINDEV:
- Create a text file
- Write into a text file
- Read in a text file
Handling text files Unit examples (WEBDEV): Handling text files
[ + ] This example explains how to handle "non HFSQL" files with WEBDEV and it allows you to:
- Create a text file
- Write into a text file
- Read in a text file
Handling text files Unit examples (WINDEV Mobile): Handling text files
[ + ] Handling external "text" files:
- Create a text file
- Write into a text file
- Read in a text file
Components
WINDEVWEBDEV - Server codeReports and Queries wd230std.dll
Windows Mobile wp230std.dll
Java wd230java.jar
Linux wd230std.so
Android wd230android.jar
Minimum required version
  • Version 9
This page is also available for…
Comments
Example ReadFile
PROCEDURE ReadFile(ArquivoTxt is string, TipoUnicodeToAnsi is string)

//Le arquivo texto
INFO(TIMESYS())

// Declare the variables
PathFile is string = ArquivoTxt
IdFile, ResCloseFile, FileID, NumeroLinha is int
Line is string

NextTitle("Atencao")

IF fFileExist(ArquivoTxt) = true

// Open the file
FileID = fOpen(PathFile,foReadWrite)
IF IdFile = -1 THEN
Error(ErrorInfo(errMessage))
ELSE

if TipoAnsiUnicode = "UnicodeToAnsi"
//Converte de Unicode para Ansi
Line = UnicodeToAnsi(fReadLine(FileID))
else
Line = fReadLine(FileID)
end

//Linha 1
NumeroLinha = 1
/// ----COLOQUE AQUI O PROGRESS BAR = 1
//Info("Linha:" + NumeroLinha, Line) ///----------------- LINHA LIDA
//Inclua aqui a SUB Procedure de importacao dos dados

WHILE Line <> EOT AND Line <> ""

//Proxima linha
NumeroLinha += 1
/// ----COLOQUE AQUI O PROGRESS BAR + 1
Line = fReadLine(FileID)
//Info("Linha:" + NumeroLinha, Line) ///----------------- LINHA LIDA
//Inclua aqui a SUB Procedure de importacao dos dados
END
IF Line = "" THEN Error(ErrorInfo(errMessage))
IF Line = EOT THEN Info("Final do Arquivo.")
ResCloseFile = fClose(IdFile)
IF ResCloseFile = -1 THEN
//Error(ErrorInfo(errMessage))
END

END

ELSE
Info("Arquivo não encontrado!")
END

info(NumeroLinha,TIMESYS())

//Codigo Desenvolvido com a Ajuda do Marcos Roberto Araujo de Carvalho de Gurupi - TO - BR
adrianoboller
Feb. 21 2015