Академический Документы
Профессиональный Документы
Культура Документы
Declaring Variables
Variables are declared using “dim” keyword. Since there is only ONE fundamental data type,
all the declared variables are variant by default. Hence, a user NEED NOT mention the type
of data during declaration.
Example 1: In this Example, IntValue can be used as a String, Integer or even arrays.
Dim Var
Example 2: Two or more declarations are separated by comma(,)
Dim Variable1,Variable2
Examples:
' Below Example, The value 25 is assigned to the variable.
Value1 = 25
Public
Variables declared using "Public" Keyword are available to all the procedures across
all the associated scripts. When declaring a variable of type "public", Dim keyword is
replaced by "Public".
Private
Variables that are declared as "Private" have scope only within that script in which
they are declared. When declaring a variable of type "Private", Dim keyword is replaced by
"Private".
If used, the Option Explicit statement must appear in a script before any procedures.
When you use the Option Explicit statement, you must explicitly declare all variables using
the Dim, Private, Public, or ReDim statements. If you attempt to use an undeclared variable
name, an error occurs.
The following example illustrates use of the Option Explicit statement:
Syntax
LCase(string)
Example 1
<script language="vbscript" type="text/vbscript">
txt="THIS IS A BEAUTIFUL DAY!"
document.write (LCase(txt))
</script>
The output of the code above will be:
this is a beautiful day!
2) StrComp Function:- The StrComp function compares two strings and returns a
value that represents the result of the comparison.
The StrComp function can return one of the following values:
-1 (if string1 < string2)
0 (if string1 = string2)
1 (if string1 > string2)
Null (if string1 or string2 is Null)
Syntax
StrComp(string1,string2[,compare])
Example 1
document.write(StrComp("VBScript","VBScript"))
Output:
0
Example 2
document.write(StrComp("VBScript","vbscript"))
Output:
-1
3) Len Function:- The Len function returns the number of characters in a string.
Syntax
Len(string)
Example
<script language="vbscript" type="text/vbscript">
txt="This is a beautiful day!"
document.write(Len(txt))
</script>
The output of the code above will be:
24
4) What is XML and XSL? Discuss in brief.
What is XML?
XML stands for eXtensible Markup Language
XML is a markup language much like HTML
XML was designed to store and transport data
XML was designed to be self-descriptive
The Difference Between XML and HTML
XML and HTML were designed with different goals:
XML was designed to carry data - with focus on what data is
HTML was designed to display data - with focus on how data looks
XML tags are not predefined like HTML tags are
XML Simplifies Things
It simplifies data sharing
It simplifies data transport
It simplifies platform changes
It simplifies data availability
XSL stands for EXtensible Stylesheet Language. XSLT is the most important part of XSL.
XSLT is used to transform an XML document into another XML document, or another type
of document that is recognized by a browser, like HTML and XHTML.
How Does it Work?
In the transformation process, XSLT uses XPath to define parts of the source
document that should match one or more predefined templates. When a match is found,
XSLT will transform the matching part of the source document into the result document.
5) Explain Looping Structures of VBScript
A loop statement allows us to execute a statement or group of statements multiple
times and following is the general from of a loop statement in VBScript.
If you want to send an invitation to 10 people with the same message then you can use ‘for
loop’ in this case as a counter is fixed and you know the message which is to be repeated 10
times.
Arithmetic Operators
Assume variable A holds 5 and variable B holds 10, then:
Operator Description Example
+ Adds two operands A + B will give 15
- Subtracts second operand from the first A - B will give -5
* Multiply both operands A * B will give 50
/ Divide numerator by denumerator B / A will give 2
% Modulus Operator and remainder of after an B MOD A will
integer division give 0
^ Exponentiation Operator B ^ A will give
10000
Comparison Operators
Assume variable A holds 10 and variable B holds 20, then
Operator Description Example
== Checks if the value of two operands are equal or not, (A == B) is
if yes then condition becomes true. False.
<> Checks if the value of two operands are equal or not, (A <> B) is
if values are not equal then condition becomes true. True.
> Checks if the value of left operand is greater than the (A > B) is
value of right operand, if yes then condition becomes False.
true.
< Checks if the value of left operand is less than the (A < B) is
value of right operand, if yes then condition becomes True.
true.
>= Checks if the value of left operand is greater than or (A >= B) is
equal to the value of right operand, if yes then False.
condition becomes true.
<= Checks if the value of left operand is less than or equal (A <= B) is
to the value of right operand, if yes then condition True.
becomes true.
Logical Operators
Assume variable A holds 10 and variable B holds 0, then:
Operator Description Example
AND Called Logical AND operator. If both the a<>0 AND
conditions are True then Expression becomes true. b<>0 is False.
OR Called Logical OR Operator. If any of the two a<>0 OR b<>0
conditions are True then condition becomes true. is true.
NOT Called Logical NOT Operator. Use to reverses the NOT(a<>0 OR
logical state of its operand. If a condition is true b<>0) is false.
then Logical NOT operator will make false.
XOR Called Logical Exclusion. It is the combination of (a<>0 XOR
NOT and OR Operator. If one, and only one, of b<>0) is true.
the expressions evaluates to True, result is True.
Concatenation Operators
Assume variable A holds 5 and variable B holds 10 then:
Operator Description Example
+ Adds two Values as Variable Values are A + B will give 15
Numeric
& Concatenates two Values A & B will give
510
</script>
</body>
</html>
Output: After trim : Microsoft VBScript
LTrim:-The Ltrim Function removes the blank spaces that are there on the left side of the
string.
Syntax
LTrim(String)
Example
<html>
<body>
<script language="vbscript" type="text/vbscript">
var = " Microsoft VBScript"
document.write("After Ltrim : " & LTrim(var) & "<br />")
</script></body>
</html>
RTrim:- The Rtrim Function removes the blank spaces that are there on the Right side of
the string.
Syntax
RTrim(String)
Example
<html>
<body>
<script language="vbscript" type="text/vbscript">
var = "Microsoft VBScript "
document.write("After Rtrim : " & RTrim(var) & "<br />")
</script></body>
</html>
Output: After Rtrim : Microsoft VBScript
9) Explain ElseIf statement with suitable example.
The basic idea of the ElseIf statement is to create an If Statement within another If
Statement. This way you can check for many different cases in a single If Statement clause.
Example:-
<script type="text/vbscript">
Dim temperature
temperature = 65
If temperature > 70 Then
document.write("Wear a T-Shirt!")
ElseIf temperature > 60 Then
document.write("Wear a hat!")
ElseIf temperature > 50 Then
document.write("Wear a long-sleeved shirt!")
Else
document.write("Wear a coat!")
End If
</script>
Output:
Wear a hat!
Here temperature was set to 65 and failed the first If Statement condition because 65
is not greater than 70. However, on the first ElseIf Statement we found that 65 was greater
than 60 and so that block of code document.write("Wear a hat!")was executed. Because there
was a success the If Statement then finishes and our VBSCript would begin again on the line
of code following End If
Syntax
The syntax of a for loop in VBScript is:
For counter = start To end [Step stepcount]
[statement 1]
[statement 2]
....
[statement n]
[Exit For]
[statement 11]
[statement 22]
....
[statement n]
Next
counter - Numeric variable used as a loop counter. The variable can't be an
array item or an item of a user-defined type.
start - Initial value of the counter variable.
end - Final value of the counter variable.
stepcount - Amount the counter variable is changed each time through the loop.
If not set, then is 1.
statements - One or more statements between For and Next that are executed
the specified number of times.
Exit-You can exit a For...Next statement with the Exit For keyword.
For Example
For i=1 To 10
If i=5 Then Exit For
some code
Next
Example
<!DOCTYPE html>
<html>
<body>
<script language="vbscript" type="text/vbscript">
Dim a=10
For i=0 to a Step 2 'i is the counter variable and it is incremented by 2
document.write("The value is : " &i)
document.write("<br></br>")
Next
</script></body></html>
Output
The value is : 0
The value is : 2
The value is : 4
The value is : 6
The value is : 8
The value is : 10
11) Difference between HTML and XML.
XML HTML
Syntax
The syntax of a for loop in VBScript is:
For counter = start To end [Step stepcount]
[statement 1]
[statement 2]
....
[statement n]
[Exit For]
[statement 11]
[statement 22]
....
[statement n]
Next
Example
<!DOCTYPE html>
<html>
<body>
<script language="vbscript" type="text/vbscript">
Dim a=10
For i=0 to a Step 2 'i is the counter variable and it is incremented by 2
document.write("The value is : " &i)
document.write("<br></br>")
Next
</script></body></html>
Output
The value is : 0
The value is : 2
The value is : 4
The value is : 6
The value is : 8
The value is : 10
While..Wend loop:-In a While..Wend loop, if the condition is True, all statements are
executed until Wend keyword is encountered.
If the condition is false, the loop is exited and the control jumps to very next statement after
Wend keyword.
Syntax
The syntax of a While..Wend loop in VBScript is:
While condition(s)
[statements 1]
[statements 2]
...
[statements n]
Wend
Example
<!DOCTYPE html>
<html>
<body>
<script language="vbscript" type="text/vbscript">
</script>
</body>
</html>
Output:-
The Current Value of the Counter is : 11
The Current Value of the Counter is : 12
The Current Value of the Counter is : 13
The Current Value of the Counter is : 14
The Current Value of the Counter is : 15
14) Explain string handling functions of VB script.
Strings are a sequence of characters, which can consist of alphabets or numbers or special
characters or all of them. A variable is said to be a string if it is enclosed within double quotes
""
Syntax
variablename = "string"
Examples
str1 = "string" ' Only Alphabets
str2 = "132.45" ' Only Numbers
str3 = "!@#$;*" ' Only Special Characters
Str4 = "Asc23@#" ' Has all the above
There are predefined VBScript String functions, which help the developers to work with the
strings very effectively. Below are String methods that are supported in VBScript.
Example
response.write(String(10,"a"))
Output:
aaaaaaaaaa
15) Explain Logical Structures of VBScript
VBScript is a ‘Scripting Language’. It is a lightweight case insensitive programming
language developed by Microsoft.
<html>
<body>
<script language="vbscript" type="text/vbscript">
document.write("Hello World!")
</script>
</body>
</html>
In the above example, we called a function document.write, which writes a string into the
HTML document. This function can be used to write text, HTML or both.
Whitespace and Line Breaks: - VBScript ignores spaces, tabs and newlines that appear
within VBScript programs
Formatting: -
Single Line Syntax:-Colons are used when two or more lines of VBScript ought to be
written in a single line.
<script language="vbscript" type="text/vbscript">
var1 = 10: var2 = 20
</script>
Multiple Line Syntax: -When a statement in VBScript is lengthy and if user wishes to break
it into multiple lines, then the user has to use underscore "_".
<script language="vbscript" type="text/vbscript">
var1 = 10
var2 = 20
Sum = var1 + var2
document.write("The Sum of two numbers"&_
"var1 and var2 is " & Sum)
</script>
Function sayHello()
msgbox("Hello there")
End Function
</script>
Calling a Function
To invoke a function somewhere later in the script, you would simple need to write
the name of that function with the Call keyword.
<script language="vbscript" type="text/vbscript">
Function sayHello()
msgbox("Hello there")
End Function
Call sayHello()
</script>
Function Parameters
<script language="vbscript" type="text/vbscript">
Sub Procedures
Sub Procedures are similar to functions but there are few differences.
Sub procedures DONOT Return a value while functions may or may not return a
value.
Sub procedures Can be called without call keyword.
Sub procedures are always enclosed within Sub and End Sub statements.
Sub mysub()
some statements
End Sub
or
Sub mysub(argument1,argument2)
some statements
End Sub
Example:
<script language="vbscript" type="text/vbscript">
Sub sayHello()
msgbox("Hello there")
End Sub
</script>
Calling Procedures
To invoke a Procedure somewhere later in the script, you would simply need to write the
name of that procedure with or without the Call keyword.
<script language="vbscript" type="text/vbscript">
Sub sayHello()
msgbox("Hello there")
End Sub
sayHello()</script>
1) Abs Function:-The Abs function returns the absolute value of a specified number.
Syntax
Abs(number)
Example 1
<%
response.write(Abs(1) & "<br />")
response.write(Abs(-1))
%>
The output of the code above will be:
1
1
2) Exp Function:- The Exp function returns e raised to a power.
Syntax
Exp(number)
Example
<%
response.write(Exp(6.7) & "<br />")
response.write(Exp(-6.7))
%>
The output of the code above will be:
812.405825167543
1.23091190267348E-03
3) Int Function:- The Int function returns the integer part of a specified number.
Syntax
Int(number)
Example 1
<%
response.write(Int(6.83227) & "<br />")
response.write(Int(6.23443))
%>
The output of the code above will be:
6
6
4) Sqr Function:- The Sqr function returns the square root of a number.
Syntax
Sqr(number)
Example
<%
response.write(Sqr(9) & "<br />")
response.write(Sqr(0) & "<br />")
response.write(Sqr(47))
%>
The output of the code above will be:
3
0
6.85565460040104
XML elements can have attributes, just like HTML.Attributes are designed to contain data
related to a specific element.
Attribute Types
Following table lists the type of attributes −
Attribute Type Description
StringType It takes any literal string as a value..
TokenizedType This is a more constrained type. The TokenizedType attributes
are given as −
ID − It is used to specify the element as unique.
IDREF − It is used to reference an ID that has been named for
another element.
IDREFS − It is used to reference all IDs of an element.
ENTITY − It indicates that the attribute will represent an
external entity in the document.
ENTITIES − It indicates that the attribute will represent
external entities in the document.
NMTOKEN − It is similar to CDATA with restrictions on
what data can be part of the attribute.
EnumeratedType There are two types of enumerated attribute −
NotationType − It declares that an element will be referenced
to a NOTATION declared somewhere else in the XML
document.
Enumeration − Enumeration allows you to define a specific
list of values that the attribute value must match.
21) Define NULL and EMPTY data type of variable.
NULL: A special subtype to represent a variable assigned with a null value
EMPTY: A special subtype to represent a variable that has not been assigned with any
value yet.