28,29. procedures subprocedure,type checking functions in VBScript

VARSHAKUMARI49 84 views 31 slides Oct 31, 2020
Slide 1
Slide 1 of 31
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31

About This Presentation

28,29. procedures subprocedure,type checking functions in VBScript


Slide Content

-
-By Varsha Kumari
Assistant Professor
CEA Department, GLA University Mathura

Procedure
Sub procedure
Type checking

Sub Procedure
EgMsgBox(“Hello”)
Function Procedure
eg. lntSum=AddNumbers(10, 20)

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.
Tags