'==============================================
' Date : 09/21/2012
' Created By : Jamil
' VB Script Basic Sub Function and Function Test
'==============================================
Option Explicit
Dim val1, val2
Dim res1, res2, res3, res4
Print "Calling a Sub function"
funcMath1 10, 25, "m"
funcMath1 10, 25, "S"
funcMath1 10, 25, "D"
funcMath1 10, 25, "A"
funcMath1 10, 25, "C"
'(1) simple calculater sub function with no return value
Function funcMath1(val1, val2, opt)
Dim result
Select Case UCase(opt)
Case "M"
result = (val1 * val2)
Print "The result of multiplying is " &val1& " With " &val2& " is " &result
Case "S"
result = (val1 - val2)
Print "The result of subtraction is " &val1& " With " &val2& " is " & result
Case "D"
result = (val1 / val2)
Print "The result of divide is " &val1& " With " &val2& " is " & result
Case "A"
result = (val1 + val2)
Print "The result of Addtion is " &val1& " With " &val2& " is " & result
Case else
msgBox "Your option "& opt &" is invalid!"
End Select
End Function
Print " "
Print "Calling a function"
call funcMath2(10, 25, "M")
call funcMath2(10, 25, "S")
call funcMath2(10, 25, "D")
call funcMath2(10, 25, "A")
call funcMath2(10, 25, "C")
'(2) simple calculater function with return value
Function funcMath2(val1, val2, opt)
Dim result, returnValue
Select Case UCase(opt)
Case "M"
result = (val1 * val2)
Print "The result of multiplying is " &val1& " With " &val2& " is " &result
Case "S"
result = (val1 - val2)
Print "The result of subtraction is " &val1& " With " &val2& " is " & result
Case "D"
result = (val1 / val2)
Print "The result of divide is " &val1& " With " &val2& " is " & result
Case "A"
result = (val1 + val2)
Print "The result of Addtion is " &val1& " With " &val2& " is " & result
Case else
msgBox "Your option "& opt &" is invalid!"
End Select
funcMath2 = result
End Function