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

March 20, 2009 at 4:58 am Leave a comment


 

March 2009
M T W T F S S
     
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Recent Posts

Top Posts

  • None

Top Clicks

  • None

Pages

Watch videos at Vodpod and other videos from this collection.

Blog Stats

  • 695 hits

Archives


Follow

Get every new post delivered to your Inbox.