Forum Discussion
AlexKaras
12 years agoCommunity Hero
Hi Leandro,
The case was that in VBScript, in order to return value from a function, one must assign the returned value to the 'variable' which corresponds to the name of the function. E.g.
Function FindObjectCaption(TargetObject)
Dim i
Dim obj
i = 2
Set obj = CreateObject("WScript.Shell")
...
FindObjectCaption = i
' use
' Set FindObjectCaption = obj
' if the function returns an object
End Function
In JScript (C#Script and C++Script) 'return' keyword is used to return the value from the function:
function FindObjectCaption(TargetObject)
{
var i;
var obj;
i = 2;
obj = new Object("WScript.Shell");
...
return i;
' use
' return = obj;
' if the function returns an object
}
The case was that in VBScript, in order to return value from a function, one must assign the returned value to the 'variable' which corresponds to the name of the function. E.g.
Function FindObjectCaption(TargetObject)
Dim i
Dim obj
i = 2
Set obj = CreateObject("WScript.Shell")
...
FindObjectCaption = i
' use
' Set FindObjectCaption = obj
' if the function returns an object
End Function
In JScript (C#Script and C++Script) 'return' keyword is used to return the value from the function:
function FindObjectCaption(TargetObject)
{
var i;
var obj;
i = 2;
obj = new Object("WScript.Shell");
...
return i;
' use
' return = obj;
' if the function returns an object
}