Archive for March 20, 2009
Function Returns multiple values? Check it out
Hello friends… this is the question oftenly asked in Interviews…
Returning a multiple values with function….
Function calc(a,b,c,d) ‘ Called Function —– Function Definition
msgbox “a is value “&a ‘ a value passed from calling function
msgbox “b is value “&b ‘ b value passed from calling function
c=a+b ‘ Calculation of c
d=a-b ‘ Calculation of d
calc=array(c,d) ‘ Assigning Calculated values in array of Function name (calc here)
End Function
res=calc(10,20,c,d) ‘Calling Function with Passing input parameters
msgbox res(0) ‘ returning a value from array of Function (calc here)
‘ User Inputs for Addition and Subtraction calculations and getting mutiple values by using Functions
Function calc(a,b,c,d)
msgbox “Value of a is “&a
msgbox “Value of b is “&b
c=cint(a)+cint(b)
d=cint(a)-cint(b)
calc=array(c,d)
End Function
a=inputbox(“Enter a value:”,”a Value”,10)
b=inputbox(“Enter b value:”,”b Value”,20)
result=calc(a,b,c,d)
msgbox ” No. of Values in an Array is ” &ubound(result)+1
iter=ubound(result)
For i= 0 to iter
msgbox “Returned Value of “&i+1&”th iteration is “&result(i),3,”Returned Value of Function”
Next
Thanks & Regards
Baba Fakruddin.D