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

Scripts - Autoload

In the Scripts options dialog box you can select a script that will be executed when you start MedCalc.

This can be useful to load a script that contains user-defined functions that are used in different other scripts, or in different MedCalc spreadsheets.

During execution of an this Autoload script, the System variable $Autoload is set to TRUE.

For example, consider the following script:

function CalcBMI(weight,height) {
	if (height>10) { 
		// height is probably in cm, convert to m
	return weight/height^2;
if (!$Autoload) {
	// test function
	?CalcBMI(70,176);  println;
	?CalcBMI(70,1.76); println;

When you run this script in the script window, the script will show the calculated BMI.

Save the file and next select it in the Script options dialog box below Autoload script. Now exit and restart MedCalc. The script is executed automatically and the function is loaded in the workspace, without generating any output (because $Autoload is TRUE and !$Autoload is FALSE). The function can now be used in scripts as well as in the MedCalc spreadsheet, as function in derived variables or filters for statistical procedures.

See also