Saltar al contenido principal
MedCalc
Enviar una copia en PDF de esta página a:
(Su dirección de correo electrónico no se añadirá a una lista de distribución)
working

Scripts - Comandos de archivo

Comandos de archivos de datos

ReadData

ReadData(nombre de archivo) carga un archivo de datos en la hoja de cálculo.

Si no se especifica ningún nombre de archivo, el programa mostrará el cuadro de diálogo 'Seleccionar archivo'.

Si se especifica el nombre del archivo, debe contener la ruta completa, por ejemplo, 'e:\documents\MedCalc\MyData.mc1'.

El archivo puede ser un archivo MedCalc (*.mc1), un archivo Excel (*.xls, *.xlsx), un archivo SPSS (*.sav) o cualquier otro archivo de datos que MedCalc pueda importar.

Para acceder a un archivo en el escritorio, puede utilizar la constante @desktoppath , p.ej

file=@desktoppath+ 'MyData.mc1' ;
ReadData(file);

SaveData

SaveData(filename) guarda los datos de la hoja de cálculo.

Si no se especifica ningún nombre de archivo, el programa mostrará el cuadro de diálogo 'Seleccionar archivo'.

Si se especifica el nombre del archivo, debe contener la ruta completa, por ejemplo, 'e:\documents\MedCalc\MyData.mc1'.

Comandos de archivo de texto

AppendFile

AppendFile(nombre_de_archivo) abre el archivo con el nombre nombre_de_archivo.

  • Si el archivo no existe, se crea.
  • Si el archivo ya existe, se abre para escritura. El puntero de archivo se coloca al final del archivo y se añade el nuevo texto al archivo existente.

CreateFile

CreateFile(nombre_archivo) crea un archivo de texto con el nombre nombre_archivo.

  • Si el archivo no existe, se crea.
  • Si el archivo ya existe, se abre para escritura y se sobrescribirá con contenido nuevo.

CreateHTML

CreateHTML(nombre_archivo) crea un archivo html con el nombre nombre_archivo.

  • Si el archivo no existe, se crea.
  • Si el archivo ya existe, se abre para escritura y se sobrescribirá con contenido nuevo.
  • La extensión del nombre del archivo no tiene que ser necesariamente htm o html. Puede usar, por ejemplo, 'informe.doc'. Los archivos HTML se pueden visualizar y editar fácilmente como un documento en Word.
  • Solo necesita proporcionar el cuerpo del archivo HTML. MedCalc agregará el encabezado hasta la parte <body> (incluida), y la parte </body> </html> al cerrar el archivo HTML. El encabezado HTML contiene el formato CSS para informes, gráficos, matrices y tablas de MedCalc.

Write

Write(nombre de archivo,datos) escribe los datos como texto en el archivo especificado.

El archivo ya debe haber sido abierto con el OpenFile o CreateHTML dominio.

En el texto a escribir, puedes incluir un código de nueva línea '\n' o un código de tabulación '\t'.

Los datos pueden ser texto, un número real, un número complejo, una matriz o una tabla.

Puedes escribir varios valores en el archivo con un solo comando de escritura. Los diferentes elementos deben separarse con el separador de lista.

Puede especificar el número de decimales añadiendo: n al elemento. Por ejemplo, write(filename,25.6123:2) escribirá 25.61 en el archivo. Esto funciona con números reales, complejos y matrices.

WriteLn

WriteLn(filename) writes a new line to the specified file.

The file must already have been opened with the OpenFile or CreateHTML command.

When you use WriteLn on a HTML file, MedCalc will insert a <br> tag.

CloseFile

CloseFile(filename) closes the file for writing.

The file must have been opened with the OpenFile or CreateHTML command.

ViewFile

ViewFile(filename) opens the file. The program that is used to view the file, is dependent on the file extension. For example, if the filename is report.doc, the file will be opened with Word (if you are using Word as text editor). If the filename is report.html, the file will be opened in a browser. Using ViewFile, you can also open a web page url like 'https://www.medcalc.org/'.

Graph file commands

SaveGraph

SaveGraph(filename,graphid) saves a graph on disk using the specified filename.

The image format is PNG or SVG and the filename must have '.png' or '.svg' as extension.

Graphid is any of the system variables $graph, $graph1, or $graph2, which represent graphs obtained after using the PROC command.

proc(scatter);
SaveGraph('d:\scatterdiagram.svg',$graph);

File functions

FileList

The FileList([ path,][ mask ]) lists the files in the given path that match the mask, into a table. The table also contains the file sizes. Both arguments are optional and default to the current directory and *.* respectively.

For example, t=FileList('*.mc1'); creates a table t containing the mc1 files in the current directory.

A file mask is a pattern of fixed and wildcard characters used to match folder and file names. These masks provide a means for identifying specific files or groups of files based on their name and extension.

Most commonly the mask consists only of an asterisk and a file extension, for example: *.mc1 to select mc1 files, *.jpg to select jpg files, etc.

SelectFolder

The SelectFolder() function takes no arguments. The function displays a dialog in which the user can select a disk folder, and retuns the selected folder.

For example, folder=SelectFolder();

GetOpenFilename

The GetOpenFilename([ path,][ mask ]) displays a dialog in which the user can select a file for reading. The filename must match the given mask. Both arguments are optional and default to the current directory and *.* respectively.

For example, file=GetOpenFilename($DataPath,'*.mc1');

GetSaveFilename

The GetSaveFilename([ ruta,][ máscara ]) muestra un cuadro de diálogo donde el usuario puede seleccionar un archivo para escribir. El nombre del archivo debe coincidir con la máscara especificada. Ambos argumentos son opcionales y, por defecto, el directorio actual y *.*, respectivamente.

Por ejemplo, archivo=GetSaveFilename($DataPath,'*.mc1');

Véase también