Saturday 1 November 2014

VB SCRIPT BY CHOKSI AHMAD


VBScript
v  VBScript is a Microsoft scripting language.
v  VBScript is the default scripting language in ASP.
v  Client-side VBScript only works in Internet Explorer!!!

Program-1    Write Text Using Vbscript.
<html>
<body>

<script type="text/vbscript">
document.write("This is my first VBScript!")
</script>

</body>
</html>
<html>
<body>

<script type="text/vbscript">
document.write("<font color=green size=7>Hello World!</font>")
</script>

</body>
</html>

<html>
<head>
<script type="text/vbscript">
function choksi()
alert("Hello World!")
end function
</script>
</head>

<body onload="choksi()">

<p>We usually use the head section for functions (to be sure that the functions are loaded before they are called).</p>

</body>
</html>


<html>
<head>
<script type="text/vbscript">
function choksi()
document.write("Hello World!")
end function
</script>
</head>

<body>
<input type="button" value="click here" onclick="choksi()">
<p>We usually use the head section for functions (to be sure that the functions are loaded before they are called).</p>

</body>
</html>

Program-5  Create A Variable.
<html>
<body>
<script type="text/vbscript">
Dim firstname
Dim lastname
firstname="ahmad"
lastname="choksi"
document.write(firstname)
document.write("<br>")
document.write(lastname)
</script>

<p>The script above declares a variable, assigns a value to it, and displays the value. Then, it changes the value, and displays the value again.</p>

</body>
</html>

<body>
<script type="text/vbscript">
Dim name,surname
name="ahmad"
surname="choksi"
document.write("My name is: " & name &"<br>")
document.write("My surname is: " & surname)
</script>
</body>
</html>


Program-7  Create an array.
<html>
<body>

<script type="text/vbscript">
Dim famname(5)
famname(0)="Jan Egil"
famname(1)="Tove"
famname(2)="Hege"
famname(3)="Stale"
famname(4)="Kai Jim"
famname(5)="Borge"
document.write(famname(5))
</script>
</body>
</html>

Program-8  Create an array.
<html>
<body>

<script type="text/vbscript">
Dim famname(5)
famname(0)="Jan Egil"
famname(1)="Tove"
famname(2)="Hege"
famname(3)="Stale"
famname(4)="Kai Jim"
famname(5)="Borge"
For i=0 To 5
                    document.write(famname(i) & "<br />")
Next
</script>
</body>
</html>
Program-9  Sub procedure.
<html>
<head>
<script type="text/vbscript">
Sub mySub()
  msgbox("This is a Sub procedure")
End Sub
</script>
</head>
<body>
<script type="text/vbscript">
Call mySub()
</script>
<p>A Sub procedure does not return a result.</p>
</body>
</html>
Program-10  Function procedure.
<html>
<head>
<script type="text/vbscript">
Function myFunction()
 myFunction = "BLUE"
End Function
</script>
</head>
<body>
<script type="text/vbscript">
document.write("My favorite color is " & myFunction())
</script>
<p>A Function procedure can return a result.</p>
</body>
</html>

Program-11 Use of Arithmetic or Math Operators.
<html>
<body>

<script type="text/vbscript">
dim a,b
a=50
b=15
document.write("Sum of a and b is="&(a+b)&"<br>")
document.write("Multiplication of a and b is="&(a*b)&"<br>")
document.write("Subtraction of a and b is="&(a-b)&"<br>")
document.write("Division of a and b is="&(a/b)&"<br>")
document.write("Modulus of a and b is="&(a mod b)&"<br>")

</script>
</body>
</html>
Program-12  Use of Comparison Operators.
<html>
<body>
<script type="text/vbscript">
dim a,b
a=50
b=15
document.write("a equal to b="&(a=b)&"<br>")
document.write("a greater than b="&(a>b)&"<br>")
document.write("a less than b="&(a<b)&"<br>")
document.write("a greater than or equal to b="&(a>=b)&"<br>")
document.write("a less than or equal to b="&(a<=b)&"<br>")
document.write("a not equal to b="&(a<>b)&"<br>")

</script>
</body>
</html>
Program-13  Use of Logical Operators.
<html>
<body>
<script type="text/vbscript">
dim a,b
a=50
b=15
dim x,y,z

if a>10 and b<20 then
                    x=true
else
                    x=false
end if
                    document.write("And operator="&(x)&"<br>")

if a<40 or b>10 then
                    y=true
else
                    y=false
end if
                    document.write("Or operator="&(y)&"<br>")

if not a=not y then
                    z=true
else
                    z=false
end if
                    document.write("NOT operator ="&(z)&"<br>")
</script>
</body>
</html>

Program-14  If  statement
<head>
<script type="text/vbscript">
dim i
i=20
If  i > 18 Then
 document.write("You are eligible for voting")
End If

</script>
</head>
Program-15  If  statement
<html>
<head>
<script type="text/vbscript">
dim i
i=20
If  i = 20 Then
                    i=i+5
                    document.write("new value of  i is="&i)
End If

</script>
</head>
</html>


<head>
<script type="text/vbscript">
dim i
i=20
If  i > 18 Then
                    document.write("You are eligible for voting")
Else
                    document.write("You are not eligible for voting")
End If

</script>
</head>

<html>
<head>
<script type="text/vbscript">
dim i
i=20
If  i > 18 Then
                    i=i+5
                    document.write("new value of a="&i)
Else
                    i=i-5
                    document.write("new value of a="&i)
End If

</script>
</head>
</html>





<html>
<body>
<script type="text/vbscript">
dim percentage
dim result
percentage=65

if percentage >70 then
                    result="distiction"
elseif percentage>=60 and percentage<70 then
                    result="first class"
elseif percentage>=50 and percentage<60 then
                    result="second class"
elseif percentage>=40 and percentage<50 then
                    result="third class"
else
                    result="pass class"
end if
                    document.write("Result is="&result)

</script>
</body>
</html>

Program-19  Select Case statement
<html>
<body>
<script type="text/vbscript">
d=4
Select Case d
  Case 1
                    document.write("Sleepy Sunday")
  Case 2
                    document.write("Monday again!")
  Case 3
                    document.write("Just Tuesday!")
  Case 4
                    document.write("Wednesday!")
  Case 5
                    document.write("Thursday...")
  Case 6
                     document.write("Finally Friday!")
  Case else
                    document.write("Super Saturday!!!!")
End Select
</script>

</body>
</html>

Program-20  For...Next Loop
Ø  Use the For...Next statement to run a block of code a specified number of times.

<html>
<body>

<script type="text/vbscript">
For i = 0 To 5
  document.write("The number is " & i & "<br />")
Next
</script>

</body>
</html>

No comments:

Post a Comment