PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Example: Opening an external file
  • Example: Opening and/or creating an external file
  • Example: Opening an external file (WEBDEV)
  • Example: Opening and/or creating an external file (WEBDEV)
Example: Opening an external file
WINDEVReports and QueriesWindows MobileJavaUser code (UMC)
The following code is used to open an external file. The file is opened in read/write mode. The file name and path are selected by fSelect.
// Declare the variables
FileNameAndPath is string
FileID is int
// Select the file name and path
FileNameAndPath = fSelect("", "", "Selecting an external file", ...
"External file" + TAB + "*.txt", "txt", fselCreate)
// 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
  // Processes in the opened file
  ...
  // End of processes
END
Example: Opening and/or creating an external file
WINDEVReports and QueriesWindows MobileJavaUser code (UMC)
The following code is used to open and/or to create an external file. The file is opened in read/write mode. The file name and path are selected by fSelect. If the file already exists, this file will not be re-created (foCreateIfNotExist constant).
// Declare the variables
FileNameAndPath is string
FileID is int
// Select the file name and path
FileNameAndPath = fSelect("", "", "Selecting an external file", ...
"External file" + TAB + "*.txt", "txt", fselCreate)
// Open the file
FileID = fOpen(FileNameAndPath, foReadWrite + foCreateIfNotExist)
// Display an error message if the creation was not performed
IF FileID = -1 THEN
  Error(ErrorInfo(errMessage))
ELSE
  // Processes in the opened file
  ...
  // End of processes
END
Example: Opening an external file (WEBDEV)
WEBDEV - Server codePHPAjax
The following code is used to open an external file. The file is opened in read/write mode.
// Declare the variables
FileNameAndPath is string
FileID 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
// Processes in the opened file
...
// End of processes
END
Example: Opening and/or creating an external file (WEBDEV)
WEBDEV - Server codePHPAjax
The following code is used to open and/or to create an external file. The file is opened in read/write mode. If the file already exists, this file will not be re-created (foCreateIfNotExist constant).
// Declare the variables
FileNameAndPath is string
FileID is int
// Select the file name and path
FileNameAndPath = "C:\MyDirectories\File.txt"
// Open the file
FileID = fOpen(FileNameAndPath, foReadWrite + foCreateIfNotExist)
// Display an error message if the creation was not performed
IF FileID = -1 THEN
Error(ErrorInfo(errMessage))
ELSE
// Processes in the opened file
...
// End of processes
END
Minimum version required
  • Version 9
This page is also available for…
Comments
Example ReadFile - Exemplo de leitura de arquivo
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())
adrianoboller
24 Feb. 2015