Skip to main content
MedCalc
Mail a PDF copy of this page to:
(Your email address will not be added to a mailing list)
working
Show menu

Scripts - File commands

Data file commands

ReadData

ReadData(filename) loads a datafile into the spreadsheet.

If no filename is specified, the program will show the "Select file" dialog box.

If the filename is specified, it should contain the full path, e.g. "e:\documents\MedCalc\MyData.mc1".

The file can be a MedCalc file (*.mc1), Excel file (*.xls, *.xlsx), SPSS file (*.sav) or any other datafile that MedCalc can import.

To access a file on the desktop, you can use the constant @desktoppath, e.g.

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

SaveData

SaveData(filename) saves the spreadsheet data.

If no filename is specified, the program will show the "Select file" dialog box.

If the filename is specified, it should contain the full path, e.g. "e:\documents\MedCalc\MyData.mc1".

Text file commands

AppendFile

AppendFile(filename) opens the file with name filename.

CreateFile

CreateFile(filename) creates a text file with name filename.

CreateHTML

CreateHTML(filename) creates a html file with name filename.

Write

Write(filename, data) writes the data as text to the specified file.

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

In the text to write, you can include a new line code "\n" or tab code "\t".

Data can be text, a real number, a complex number, a matrix or a table.

You can write several values to the file using one single Write command. The different items need to be separated with the list separator.

You can specify the number of decimals by adding :n to the item. For example, write(filename,25.6123:2) will write 25.61 to the file. This works for real numbers, complex numbers and 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 webpage url like "https://www.medcalc.org/".

See also