AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de archivos externos
  • Example: Opening a selected file
  • Example: Opening a selected sound file
  • Handling a multi-file picker
Example: Opening a selected file
WINDEVJavaCódigo de Usuario (UMC)
The following code is used to open a selected file. The file picker is opened in file opening mode (fselOpen constant). Only the existing files are displayed in the file picker (fSelExist constant). The selected file is opened in read/write.
// Declare the variables
FileNameAndPath is string
FileID is int
// Select file to open
FileNameAndPath = fSelect("C:\MyDirectories", "File.txt", ...
	"Select a file", "Text file (*.TXT)" + TAB + ...
	"*.txt" + CR + "All files (*.*)" + TAB + "*.*", "TXT", fselOpen + fselExist)
// Open file
FileID = fOpen(FileNameAndPath, foReadWrite)
// Display an error message if no file was opened
IF FileID = 1 THEN
   	Error(ErrorInfo(errMessage))
ELSE
   	// Processes in the opened file
   	...
   	// End of processes
END
Example: Opening a selected sound file
WINDEVJavaCódigo de Usuario (UMC)
The following code is used to select a sound file (".WAV"). The file picker is opened in opening mode (fselOpen constant). Only the existing files are displayed in the file picker (fSelExist constant). When a click is performed on a file found in the file picker, the sound is played.
// --Code for window creation
GLOBAL
	FileNameAndPath is string
// --Click code on BTN_SelectFile
// Initialization code
EventNum is int
// Declare the event used to play the selected sound file
EventNum = Event("PlaySound", WinInput(), 1624)
// Select a sound file
FileNameAndPath = fSelect("C:\MyDirectories", "", "Select a sound file", ...
		"Wave sound (*.WAV)" + TAB + "*.wav", "", fselOpen + fselExist + fselChange)
// End of event
EndEvent(EventNum)
// Processes in the selected file
...
// End of processes
// Procedure local to the window. This procedure is used to play the sound file
PROCEDURE PlaySound(wMessage, wParam, lParam)
FileName is fixed string of 261
// The file path cannot exceed 260 characters.

// Retrieve the string that contains the name of the file currently selected
//Transfer(&FileName, lParam, wParam)
FileName = StringRetrieve(lParam, srUnicodeAddress)
// FileName: string containing the name of the currently selected file
// lParam: address of the string containing the name of the file currently selected
// wParam: size of the string containing the name of the file currently selected

// Run the selected sound file
Sound(FileName)
Handling a multi-file picker
WINDEV
// Variables
sDocumentPath is string
sNewPath is string
sExtension is string
sAllDocuments is string
nCtr is int

// Initialize the variables
sAllDocuments = fSelect("C:\", "All files", ...
	"Select the document to save", "*.*", "*.*", fselOpen + fselMulti)

nCtr = 1

// Browse each document
sDocumentPath = ExtractString(sAllDocuments, nCtr, CR)
HourGlass()
WHILE sDocumentPath <> EOT 
	// Specific process if this file is an image
	sExtension = Upper(fExtractPath(sDocumentPath, fExtension)) 
	IF sExtension = ".GIF" OR sExtension = ".BMP" OR  ...
			sExtension = ".JPG" OR sExtension = ".JPEG" THEN
		// Call to the component for writing notes in the images
		Open(WIN_ImageZoom, sDocumentPath, 80) 
	END
	IF HLinkMemo(DOC_Contact, Document, sDocumentPath, hMemoBin) = False THEN
		Error(HErrorInfo())
	ELSE
		// Assign the values
		DOC_Contact.ContactID = ID_Of_Contact 
		DOC_Contact.Caption = fExtractPath(sDocumentPath, fFileName) 
		DOC_Contact.Format = Middle(fExtractPath(sDocumentPath, fExtension), 2, 3) 
		DOC_Contact.Date = DateSys()
		DOC_Contact.Comments = Open(WIN_Enter_Comments, sDocumentPath)
		// Add the folder
		IF HAdd(DOC_Contact) = False THEN Error(HErrorInfo()) 
	END
	// Process the next document
	nCtr ++ 
	sDocumentPath = ExtractString(sAllDocuments, nCtr, CR)
END
HourGlass(False)
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: 29/10/2024

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