PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Example: Reading a block of bytes in an external file
  • Example: Reading a fixed-length character string
  • Example: Transferring data from a text file into a memory section
  • Example: Reading a block of bytes in an external file (WINDEV Mobile)
  • Example: Transferring data from a text file to a memory section (WINDEV Mobile)
Example: Reading a block of bytes in an external file
WINDEVWEBDEV - Server codeReports and QueriesJavaPHPAjaxUser code (UMC) 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 the 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, 13)
// 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
Example: Reading a fixed-length character string
WINDEVWEBDEV - Server codeReports and QueriesAjaxUser code (UMC) 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 memory block (identified by its address) before it is displayed in the edit control.
// 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 the 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
Example: Transferring data from a text file into a memory section
WINDEVReports and QueriesUser code (UMC) 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 the 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
Example: Reading a block of bytes in an external file (WINDEV Mobile)
Windows Mobile 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 the file
FileID = fOpen("\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, 13)
// 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
Example: Transferring data from a text file to a memory section (WINDEV Mobile)
Windows Mobile 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 the file
FileID = fOpen("\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
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment