Tuesday 23 June 2020

24 - Web Designing Question - 04


In VBScript, function can return multiple values

(A)    Yes

(B)    No

A VBScript function can have an optional return statement. This is required if you want to return a value from a function. For example, you can pass two numbers in a function and then you can expect from the function to return their multiplication in your calling program.

NOTE − A function can return multiple values separated by comma as an array assigned to the function name itself.

Example

This function takes two parameters and concatenates them and returns result in the calling program. In VBScript, the values are returned from a function using function name. In case if you want to return two or more values, then the function name is returned with an array of values. In the calling program, the result is stored in the result variable.

Return a single value from a function

<script language = "vbscript" type = "text/vbscript">

         Function concatenate(first, last)

            Dim full

            full = first & last

            concatenate = full  'Returning the result to the function name itself

         End Function

         ' Here is the usage of returning value from  function.

         dim result

            result = concatenate("Zara", "Ali")

        msgbox(result)

      </script>

 

 

 Return multiple values from a function

 

<script type="text/vbscript">

Function func(a, b)

mul=a*b

div=a/b

m=a+b

n=a-b

func = Array(mul,div,m,n)

End Function

 

dim val

val = func(3,4)

document.write("mul=" & val(0) & "<br/>")

document.write("div=" & val(1) & "<br/>")

document.write("add=" & val(2) & "<br/>")

document.write("sub=" & val(3) & "<br/>")

</script>

 

Output

mul=12
div=0.75
add=7
sub=-1

 



So Answer is (A) Yes 

No comments:

Post a Comment