AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de archivos externos
Reportes y Consultas Example: Reading a block of bytes in an external file
The following code is used to read a block of bytes in an external file. The text file is opened in read/write.
We assume that the text file contains: "Easy and fast programming!". The first 13 characters correspond to: "Easy and fast".
// Declare the variables
FileID is int
ResRead is string
ResCloseFile is int
// Open file
FileID = fOpen("C:\MyDirectories\Slogan.TXT", foReadWrite)
// Display an error message if the opening was not performed
IF FileID = -1 THEN
Error(ErrorInfo(errMessage))
ELSE
// Read the first 23 bytes (characters) in the file
ResRead = fRead(FileID, 23)
// Display an error message if the reading was not performed
IF ResRead = "" THEN
Error(ErrorInfo(errMessage))
ELSE
// Display the set of bytes read
Info(ResRead) // Displays "Easy and fast"
END
// Close the file
ResCloseFile = fClose(FileID)
IF ResCloseFile = -1 THEN
// Display an error message if the closing was not performed
Error(ErrorInfo(errMessage))
END
END
Reportes y Consultas Example: Reading a fixed-length character string
The following code is used to display the content of a text file in an edit control (EditFile). Each read operation corresponds to a fixed-length character string (50 bytes). The text file is opened in read/write. The content of the text file is assigned to a block (identified by its address) before it is displayed in the edit control populated programmatically.
// Declare the variables
FileNameAndPath is string
FileID is int
ResRead is int
DataToRead is ASCII string 50
ResCloseFile is int
 
// Select the file name and path
FileNameAndPath = "C:\MyDirectories\File.txt"
// Open file
FileID = fOpen(FileNameAndPath, foReadWrite)
// Display an error message if the opening was not performed
IF FileID = -1 THEN
Error(ErrorInfo(errMessage))
ELSE
// Read the first 50 bytes in the file
ResRead = fRead(FileID, 50, &DataToRead)
// Display the first bytes read in the edit control
EDT_EditFile = DataToRead
// Other data to read? Read error?
WHILE ResRead <> 0
// Read the next data in the file
ResRead = fRead(FileID, 50, &DataToRead)
// Display the next set of data in the edit control
EDT_EditFile = EDT_EditFile + DataToRead
END
// Display an error message if the reading was not performed
IF ResRead = 0 THEN Error(ErrorInfo(errMessage))
// Close the file
ResCloseFile = fClose(FileID)
IF ResCloseFile = -1 THEN
// Display an error message if the closing was not performed
Error(ErrorInfo(errMessage))
END
END
Reportes y Consultas Example: Transferring data from a text file into a memory section
The following code is used to read a composite variable (WindowStruct) stored in a text file. This structure corresponds to the position and aspect of the window at a given time. This information is then transferred into a memory section (identified by its address).
// Declare the variables
FileID is int
WindowStruct is composed of
HorizontalPos,VerticalPos are int
Width, Height are int
END
ResRead is int
ResCloseFile is int
// Open file
FileID = fOpen("C:\Temp\WindowFile.txt", foReadWrite)
// Display an error message if the opening was not performed
IF FileID = -1 THEN
Error(ErrorInfo(errMessage))
ELSE
// Read the content of the text file
ResRead = fRead(FileID, Dimension(WindowStruct), &WindowStruct)
// Display an error message if the reading was not performed
IF ResRead = 0 THEN Error(ErrorInfo(errMessage))
// Close the file
ResCloseFile = fClose(FileID)
IF ResCloseFile = -1 THEN
// Display an error message if the closing was not performed
Error(ErrorInfo(errMessage))
END
END
// Modify the position and size of the window
MyWindow..X = WindowStruct.HorizontalPos
MyWindow..Y = WindowStruct.VerticalPos
MyWindow..Width = WindowStruct.Width
MyWindow..Height = WindowStruct.Height
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 25/08/2022

Señalar un error o enviar una sugerencia | Ayuda local