Saturday, December 6, 2008

VB Script Procedures

'There are two types of procedures

'1. Function Procedure
'2. Sub Procedure

'Function Procedure-A Function procedure is a series of VBScript statements enclosed by the Function
'and End Function statements. Function Procedure can able to return the value.

'Example:

Function demo_add(a,b)

demo_add=a+b

End Function

oVal=demo_add( 2,3)

msgbox oVal 'Returns 5

'In this example demo_add function returns a value to oVal.
'In Function procedures we can use function name to assign a value.

'Sub Procedure-A Sub procedure is a series of VBScript statements enclosed by the Sub
'and End Sub statements. Sub Procedure cannot return any value.

'Example:

Sub demo_sub(a,b, c)
c=a+b
End sub

demo_sub 2,3,x
msgbox x 'Returns 5

'This example will do the same as what function procedure is doing above.
'But in sub Procedure we need to use one more parameter to get values from the sub procedure.

No comments:

Post a Comment