In the script we have the lowest call the function, simply by typing its name. A function may also receive variable, for example, create a function that prints the factorial.
Code:
<script language="vbscript">
function factorial (number)
dim c, result
result = 1
for c = 1 to number
result = result * c
next
document.write "Factorial of" & number & "is" & result
end function
</ Script>
<script language="vbscript">
factorial (5)
</ Script>
Finally, a function can also return a value.
Code:
<script language="vbscript">
function factorial (number)
dim c, result
result = 1
for c = 1 to number
result = result * c
next
result = factorial
end function
</ Script>
<script language="vbscript">
document.write "The factorial of 5 is" & factorial (5)
</ Script>
For us to return the value, it was enough to put before the exit of the function, the function name equal to the value to return. Another way to create functions is through the command SUB. With the SUB command procedures are created. The procedure is that the functions can receive the parameters, but the procedures do not value and therefore can not be used in expressions.
Bookmarks