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.
- If the file does not exist, it is created.
- If the file already exists, it is opened for writing. The filepointer is placed at the end of the file and new text is appended to the existing file.
CreateFile
CreateFile(filename) creates a text file with name filename.
- If the file does not exist, it is created.
- If the file already exists, it is opened for writing and will be overwritten with new content.
CreateHTML
CreateHTML(filename) creates a html file with name filename.
- If the file does not exist, it is created.
- If the file already exists, it is opened for writing and will be overwritten with new content.
- The file name extension does not have to be htm or html. You can use for example 'report.doc' as a filename. HTML files can easily be viewed and further edited as a document in Word.
- You only need to provide the body part of the HTML file. MedCalc will add the header up to and including the <body> part) and the MedCalc will add the </body> </html> part when you close the HTML file. This HTML header contains CSS formatting for MedCalc reports, graphs, matrices and tables.
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/".