PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Example: Retrieving the current position in an external file
  • Example: Modifying the current position in an external file
  • Example: Positioning in an external file from the end of file
  • Example: Retrieving the current position in an external file (WEBDEV)
  • Example: Modifying the current position in an external file (WEBDEV)
Example: Retrieving the current position in an external file
WINDEVReports and QueriesWindows MobileJavaUser code (UMC) The following code is used to retrieve the current position in an external file after reading a block of bytes. The text file is opened in read/write. The name and the path of the text file are selected by fSelect.
// Declare the variables
FileNameAndPath is string
FileID is int
ResRead is string
ResPosition is int
ResCloseFile is int
 
// Select the file name and path
FileNameAndPath = fSelect("", "", "Selecting an external file", ...
"External file" + TAB + "*.txt", "txt", fselCreate)
// 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 1000 bytes in the file
ResRead = fRead(FileID, 1000)
// Display an error message if the reading was not performed
IF ResRead = "" THEN
Error(ErrorInfo(errMessage))
ELSE
// Current position?
ResPosition = fSeek(FileID, 0, fpCurrent)
// Display the position of the pointer
IF ResPosition <> -1 THEN
Info("The current position is:" + ResPosition)
ELSE
// Display the error message if a problem occurred with fSeek
Error(ErrorInfo(errMessage))
END
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: Modifying the current position in an external file
WINDEVReports and QueriesWindows MobileJavaUser code (UMC) The following code is used to write a character string from the current position. The text file is opened in read/write. The name and the path of the text file are selected by fSelect.
// Declare the variables
FileNameAndPath is string
FileID is int
ResPosition is int
SizeWritten is int
ResCloseFile is int
 
// Select the file name and path
FileNameAndPath = fSelect("", "", "Selecting an external file", ...
"External file" + TAB + "*.txt", "txt", fselCreate)
// Open file
FileID = fOpen(FileNameAndPath, foReadWrite)
// Display an error message if the opening was not performed
IF FileID = -1 THEN
    Error(ErrorInfo(errMessage))
ELSE
  // Position on byte 150
  ResPosition = fSeek(FileID, 150, fpBeginning)
  IF ResPosition = -1 THEN
      // Display an error message if the positioning was not performed
      Error(ErrorInfo(errMessage))
  ELSE
    // Write the character string from the current position
    SizeWritten = fWrite(FileID, "Sales progression")
    // Display an error message if the writing was not performed
    IF SizeWritten = -1 THEN Error(ErrorInfo(errMessage))
  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: Positioning in an external file from the end of file
WINDEVReports and QueriesWindows MobileJavaUser code (UMC) The following code is used to point to the 100th byte from the end of the file.
// Declare the variables
FilePosition is int // Current position in the file
FileName is string     // Name of the test file
FileNum is int = 0  // identifier used to handle the test file

// Select the file name and path
FileName = fSelect("", "", "Selecting an external file", ...
"External file" + TAB + "*.txt" , "txt", fselCreate)
// Open the file in read-only
FileNum = fOpen(FileName, foRead)
// Check the opening of the test file
IF FileNum = -1 THEN
  // An error occurred while opening the file
  Error("Error while opening the file" + ...
FileName, ErrorInfo())
  RETURN
ELSE
  // Position from the end
  FilePosition = fSeek(FileNum, -100, fpEnd)
  IF FilePosition <> -1 THEN
      // Read 20 characters from the current position
      Info(fRead(FileNum, 20))
  ELSE
      Info(ErrorInfo())
  END
  // Close the file
  fClose(FileNum)
END
Example: Retrieving the current position in an external file (WEBDEV)
WEBDEV - Server codePHPAjax The following code is used to retrieve the current position in an external file after reading a block of bytes. The text file is opened in read/write.
// Declare the variables
FileNameAndPath is string
FileID is int
ResRead is string
ResPosition is int
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 1000 bytes in the file
ResRead = fRead(FileID, 1000)
// Display an error message if the reading was not performed
IF ResRead = "" THEN
Error(ErrorInfo(errMessage))
ELSE
// Current position?
ResPosition = fSeek(FileID, 0, fpCurrent)
  // Display the position of the pointer
  IF ResPosition <> -1 THEN
Info("The current position is: " + ResPosition)
  ELSE
// Display the error message if a problem occurred with fSeek
  Error(ErrorInfo(errMessage))
  END
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: Modifying the current position in an external file (WEBDEV)
WEBDEV - Server codePHPAjax The following code is used to write a character string from the current position. The text file is opened in read/write.
// Declare the variables
FileNameAndPath is string
FileID is int
ResPosition is int
SizeWritten is int
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
// Position on byte 150
ResPosition = fSeek(FileID, 150, fpBeginning)
IF ResPosition = -1 THEN
// Display an error message if the positioning was not performed
Error(ErrorInfo(errMessage))
ELSE
// Write the character string from the current position
SizeWritten = fWrite(FileID, "Sales progression")
// Display an error message if the writing was not performed
IF SizeWritten = -1 THEN Error(ErrorInfo(errMessage))
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
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment