1) To return a value from a
function, you need to use the statement functionName = ReturnValue,
where functionName is the actual name of the function and ReturnValue is the
value you want to return.
2) To capture the returned value,
you need to use the statement someVariable =functionName(parameters) while
calling the function.
Let us understand this with the help of an
example.
Returning value from a Function
Returning value from a Function
'==========================================================
' Function Name:
fnSum(var1, var2)
' Function Scope: Public
' Parameters: var1 and var2-
Enter a number , result will display Sum
' Description: To find
addition of two numbers
'
Author : Hardeep
'==========================================================
Function fnSum(var1, var2)
vrSum = var1 + var2 'return the result
fnSum = vrSum
'This Statement Returns the value from
Function i.e. functionName = ReturnValue
End Function
'Calling the Function and capturing the
return value in variable "vrResult"
Dim vrResult
vrResult = fnSum(25,10)
'parameters should be passed using
parenthesis when the function returns a value
msgbox vrResult
No comments:
Post a Comment