cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Snoopstah
Level 7

Installscript function to return multiple values

How do I get an installscript function to return multiple values. I realise the help says to use BYREF, but I'm not passing any parameters TO the function, I just want to return 3 values.

Kinda like this :


export prototype STRING GetSQLDir;

//---------------------------------------------------------------------------
// GetSQLDir
//
// Function to be run during an upgrade and new install.
// Determine the path to SQL Server data and log files
// Determine the path to SQL Server backup files
//---------------------------------------------------------------------------
function string GetSQLDir()
STRING svFnSQLPath, svFnSQLBackupPath, svFnSQLDataPath;

begin

svFnSQLPath = "C:\test";
svFnSQLBackupPath = "C:\test\backup";
svFnSQLDataPath = "C:\test\data";


return svFnSQLPath, svFnSQLBackupPath, svFnSQLDataPath;
end;
Labels (1)
0 Kudos
(4) Replies
Holger_G
Level 10

You must pass the parameters to the function by reference.

-Nick
0 Kudos
Snoopstah
Level 7

Ok, thanks. Still just a little confused with the syntax. Can you please help me out?


export prototype GetSQLDir( BYREF STRING, BYREF STRING, BYREF STRING);

//---------------------------------------------------------------------------
// GetSQLDir
//
// Function to be run during an upgrade and new install.
// Determine the path to SQL Server data and log files
// Determine the path to SQL Server backup files
//---------------------------------------------------------------------------
function STRING GetSQLDir(svSQLPath, svSQLBackupPath, svSQLDataPath)
STRING svServerName, svComputerName, svServerInstance;
STRING szKey, szName;
NUMBER nBuffer, nvType, nvSize, nStartPoint, nvComputerName, nLength;

begin
//Code here to set the 3 variables
svSQLPath = "C:\TEST";
svSQLBackupPath = "C:\Test\Backup";
svSQLDataPath = "C:\Test\Data";

return svSQLPath, svSQLBackupPath, svSQLDataPath;
end;


I realise I'm off with the syntax somewhere.. can you please let me know how I should be using this?
0 Kudos
esiemiat
Level 9

To return a value through a BYREF parameter you just have to change its value like you do in the following code.


//Code here to set the 3 variables
svSQLPath = "C:\TEST";
svSQLBackupPath = "C:\Test\Backup";
svSQLDataPath = "C:\Test\Data";


When you use use BYREF a pointer to the actual memory address of the variable is passed into the function so any changes made to the parameter automatically get passed back out of the function.

You only need to use RETURN when the value is getting passed back through the function name. Meaning the calling statement looks like the following sample.


sSqlDir = GetSQLDir(sPath, sBackupPath, sDataPath)
0 Kudos
Snoopstah
Level 7

Awesome!!! Thanks for that. All good now 🙂
0 Kudos