Documente Academic
Documente Profesional
Documente Cultură
Writing output:
first.html
<html>
<body>
<script type = "text/vbscript">
document.write ("<h1><center>Generic Solutions</h1></center> ")
</script>
</body>
</html>
ext.vbs , first1.html
ext.vbs
document.write("<h1><center>Generic Solutions</center></h1>")
document.write("<h2><center>Plano,TX</center></h2>")
first1.html
<html>
<head>
<script type="text/vbscript" src="ext.vbs">
</script>
</head>
<body>
</body>
</html>
ext.vbs
Option Explicit
document.write("<h1><center>Generic Solutions</center></h1>")
document.write("<h2><center>Plano,TX</center></h2>")
Dim Batch
Dim Student(3)
Batch = "Batch1"
Student(0) = "Lavanya"
Student(1) = "Jayashri"
Student(2) = "Meena"
document.write("Batch name is " & Batch & "<br />")
document.write("List of students <br />")
document.write(Student(0) &"<br />")
document.write(Student(1) &"<br />")
document.write(Student(2) &"<br />")
Dynamic Arrays:
<html>
<head>
<script type="text/vbscript">
Dim array_dynamic()
ReDim array_dynamic(2)
array_dynamic(0) = 1
array_dynamic(1) = 2
array_dynamic(2) = 3
MsgBox array_dynamic(2)
</script>
</head>
<body>
</body>
</html>
Conditional Statements:
first1.html
<html>
<head>
<script type="text/vbscript" src="ext.vbs"></script>
<script type="text/vbscript" src="cond.vbs"></script>
</head>
<body>
</body>
</html>
Cond.vbs
Dim d
d=weekday(date)
If d=4 then
document.write("VBScript Class today at 6.00 PM")
End If
Cond.vbs
Dim d
d=weekday(date)
If d=4 then
document.write("VBScript Class today at 6.00 PM")
ElseIf d=5 then
document.write("Operational Management Class at 6.00 PM")
Else
document.write("No Class today")
End If
Cond.vbs
Dim d
d=weekday(date)
Select Case d
Case 2
document.write("XMl Class")
Case 3
document.write("EDI Class")
Case 4
document.write("VBScript Class")
Case else
document.write("No Class")
End Select
Looping For ----- Next Loop , Do --- Loop ,
Ext.vbs
Option Explicit
document.write("<h1><center>Generic Solutions</center></h1>")
document.write("<h2><center>Plano,TX</center></h2>")
Dim Batch , i
Dim Student(3)
Batch = "Batch1"
document.write("Batch name is " & Batch & "<br />")
document.write("List of students <br />")
Student(0) = "Lavanya"
Student(1) = "Jayashri"
Student(2) = "Meena"
For i = 0 To 2
document.write(Student(i) &"<br />")
Next
<html>
<body>
<script type="text/vbscript">
Sub ConvertTemp()
Function Celsius(fDegrees)
Celsius = (fDegrees - 32) * 5 / 9
End Function
Call ConvertTemp()
</script>
</body>
</html>
------------------------------------------------------------------------------------------------------------------------------------------------------------------
<html>
<head>
<script type="text/vbscript">
call square()
Function do_square(number)
do_square = number * number
End Function
Sub square()
var1 = InputBox("Please enter a number")
MsgBox ("The square is " & do_square(var1))
End Sub
</script>
</head>
<body>
</body>
</html>
Pass by Value and Pass by reference:
<html>
<head>
<script type="text/vbscript">
Sub mySub()
MsgBox "hI"
Dim X
X=2
document.write("in mysub" & X)
Call newsub(x)
document.write("Back in mysub" & X)
End Sub
Call mySub()
</script>
</body>
</html>
Chaange ByVal to ByRef and see the difference in output.
--------------------------------------------------------------------------------------------------------------------------------------
VBScript for some validation:
Eg:1
<html>
<head>
<script type="text/vbscript">
Sub DisplayData()
If Len(Document.InputForm.firstname.Value) > 5 Then
MsgBox "You have entered too many characters! You need fewer characters before I will submit this form"
End If
End Sub
</script>
</head>
<body>
<form name ="InputForm">
First name: <input type="text" name="firstname" /><br />
Last name: <input type="text" name="lastname" />
<button onclick="DisplayData()">OK</button>
</form>
</body>
</html>
Eg:2
<HEAD>
<TITLE>Working With VBScript</TITLE>
<script type="text/vbscript">
Option Explicit
Sub cmdSubmit()
If (Len(document.InputForm.txtAge.value) = 0) Then
Exit Sub
End If
If (Not(IsNumeric(document.InputForm.txtAge.value))) Then
Exit Sub
End If
End Sub
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="InputForm">
<button onclick="cmdSubmit()">OK</button>
</FORM>
</BODY>
</HTML>
VBScript Classes
Class Hello_World
Public Sub Say_Hello(Name)
MsgBox "Hello, " & Name & ", welcome to " & Garden & "."
End Sub
Public Garden
End Class
Dim MyHello_World
Set MyHello_World = New Hello_World
MyHello_World.Garden = "Fountain"
MyHello_World.Say_Hello "Sachin"
Property Let will allow code outside of the class to assign a value to a private
variable of the class.
Property Get will allow code outside of the class to read the value of a private
property variable.
Class welcome
Private ur_name
Public Property Let Name(var_name)
ur_name =var_name
End Property
End Function
End Class
Dim my_object
Set my_object = New welcome
With my_object
.Name = "sachin"
.Showwelcome "Informal"
.Showwelcome "Formal"
.Showwelcome "Casual"
End With
Set my_object = Nothing
The Class_Terminate event is fired when the object goes out of scope, or when
object is set to Nothing.
<html>
<body>
<script type="text/vbscript">
Dim temp
Dim Cel
Cel = Celsius(temp)
msgbox Cel
Function Celsius(fDegrees)
Celsius = (fDegrees - 32) * 5 / 9
End Function
</script>
</body>
</html>
<html>
<body>
<script type="text/vbscript">
Dim A, B , C
C = FunMul(A,B)
msgbox "The product of" & A & "and" & B & "is" & C
Function FunMul(A,B)
FunMul = A * B
End Function
</script>
</body>
</html>
-------------------------------------------------------------------
This program accepts two values and outputs its product
<html>
<body>
<script type="text/vbscript">
Dim A, B , C
Sub AcceptValues()
End Sub
Function FunMul(A,B)
FunMul = A * B
End Function
Call AcceptValues()
Call AcceptValues()
</script>
</body>
</html>
--------------------------------------------------------------------
Same program as above but uses for loop to execute procedure 2 times
<html>
<body>
<script type="text/vbscript">
Dim A, B , C , i
Sub AcceptValues()
End Sub
Function FunMul(A,B)
FunMul = A * B
End Function
for i = 1 to 2
Call AcceptValues()
Next
encapsulation means that the internal representation of an object is generally hidden from view outside of the object's definition