In VBScript, the difference between a function and a procedure lies in the way they are called and the way they return values.
1. Function:
- A function is a block of code that performs a specific task and returns a value.
- It is called using its name followed by parentheses, and it can be assigned to a variable or used in an expression.
- Functions can accept parameters/arguments and return a value using the `Return` statement.
- Example:
```html
<script language="vbscript">
Function AddNumbers(num1, num2)
AddNumbers = num1 + num2
End Function
Result = AddNumbers(5, 3)
document.write "The result is: " & Result
</script>
```
2. Procedure:
- A procedure is a block of code that performs a specific task without returning any value.
- It is called using its name followed by parentheses, and it cannot be assigned to a variable or used in an expression.
- Procedures can accept parameters/arguments but do not return any value.
- Example:
```html
<script language="vbscript">
Sub GreetUser(name)
document.write "Hello, " & name
End Sub
Call GreetUser("John")
</script>
```
In summary, a function returns a value while a procedure does not. Both can accept parameters, but only functions can be used in expressions.
Please login or Register to submit your answer