Similar to functions but does not return a value while function
may or may not return a value.
Sub Procedure_name()
Statement…
………………….
End Sub
Procedure_name
Procedure_name()
Call Procedure_name()
<html>
<body>
<script type="text/vbscript">
Sub sayHello()
msgbox("Hello world")
End Sub
sayHello()
</script>
</body>
</html>
<html>
<body>
<script type="text/vbscript">
Sub printval(val)
Msgbox(val)
End Sub
printval(5)/ call printval(5)
</script>
</body>
</html>
Cannot invoke subprocedure in an expression
<script type="text/vbscript">
sub square()
Dim x
x=10
End sub
document.write(x &"<br>"&square())
</script>
<html>
<body>
<script type="text/vbscript">
sub method1()
document.write("hello")
method2()
End sub
sub method2()
document.write("world")
End sub
method1()
</script>
</body>
</html>
<html>
<body>
<script type="text/vbscript">
Sub printval(val1,val2)
Msgbox(val1 & val2)
End Sub
Printval 5,10 / call printval(5,10)
</script>
</body>
</html>
is a group of reusable code which can be called anywhere in
your program
Syntax
Function Function_name()
Statement….
……………….…
End Function
Call Function_name()
X= function_name()
function_name val1, val2
<html>
<body>
<script type="text/vbscript">
Function sayHello()
msgbox("Hello there")
End Function
</script>
Call sayHello()
</body>
</html>
<html>
<body>
<script language="vbscript" type="text/vbscript">
Function sayHello(name, age)
msgbox( name & " is " & age & " years old.")
End Function
Call sayHello(“ABC", 20)
</script>
</body>
</html>
<html>
<body>
<script type="text/vbscript">
Function square(no)
Square= no*no
End function
Dim temp
temp=square(5)
MsgBoxtemp
</script>
</body> output: 25
</html>
<html>
<body>
<script type="text/vbscript">
Dim temp
for i=0 to 5
temp=square(i)
document.write(temp &"<br>")
next
Function square(no)
if no=3 then
exit function
end if
Square= no*no
End function
</script>
</body>
</html>
A function can return multiple values separated by comma
<html>
<body>
<script type="text/vbscript">
Function concatenate(first, last)
Dim full
full = first & last
concatenate = full
End Function
dim result
result = concatenate("123", "abc")
msgbox(result)
</script>
</body>
</html>
<html>
<body>
<script type="text/vbscript">
Function retval(val)
retval= val+val
document.write(val*val& "<br>")
document.write("hello" & "<br>")
End Function
dim result
result = retval(3)
document.write(result & "<br>")
</script>
</body>
</html>
output: 9
hello
6
<html>
<body>
<script type="text/vbscript">
Function add(input1,input2)
add = input1 * input1
add = input2 * input2
End Function
dim result
result = add(2,3)
document.write(result)
</script> output: 9
</body>
</html>
<script type="text/vbscript">
function add(input1,input2)
Dim temp1,temp2,temp
temp1= input1*input1
temp2= input2*input2
temp = temp1 & "*" & temp2
add = temp
end function
dim result
result = add(2,3)
document.write("Result value : "& result& "<br />")
a=Split(result,"*")
b=ubound(a)
For i=0 to b
document.write(a(i)& "<br />")
Next</script>
<script type="text/vbscript">
function add(input1,input2)
Dim temp1,temp2,temp
temp1= input1*input1
temp2= input2*input2
temp = temp1 & "*" & temp2
add = temp
end function
dim result
result = add(2,3)
document.write("Result value : "& result& "<br />")
a=Split(result,"*")
b=ubound(a) Output:
For i=0 to b Result value : 4*9
document.write(a(i)& "<br />") 4
Next</script> 9
<html>
<body>
<script type="text/vbscript">
Function add(input1,input2,output1,output2)
output1 = input1 * input1
output2 = input2 * input2
End Function
call add(2,3,x,y)
document.write(x & "<br>")
document.write(y) Output:
</script> 4
</body> 9
</html>
<html>
<body>
<script type="text/vbscript">
Function fnadd(Byval num1, Byval num2)
num1 = 4
num2 = 5
End Function
Dim x,y
x=6
y=4
res= fnadd(x,y)
document.write("The value of x is " & x & "<br />")
document.write("The value of y is " & y & "<br />")
</script>
</body>
</html>
Output :
The value of x is 6
The value of y is 4
<html>
<body>
<script language="vbscript" type="text/vbscript">
Function fnadd(ByRefnum1, ByRefnum2)
num1 = 4
num2 = 5
End Function
Dim x,y
x=6
y=4
res= fnadd(x,y)
document.write("The value of x is " & x & "<br/>")
document.write("The value of y is " & y & "<br/>")
</script>
</body>
</html>
Output :
The value of x is 4
The value of y is 5
VarType(expression) returns an integer code that corresponds
to the data type.
TypeName(expression) returns a string with the name of the
datatype rather that a code.
IsNumeric(expression) returns a Boolean value of True if the
expression is numeric data, and false otherwise.
IsArray(expression) returns a Boolean value of True if the
expression is an array, and false otherwise.
IsDate(expression) returns a Boolean value of True if the
expression is date/time, and false otherwise.
IsEmpty(expression) returns a Boolean value of True if the
expression is an empty value, and false otherwise.
IsNull(expression) returns a Boolean value of True if the
expression contains no valid data, and false otherwise.