Explore model answers categorized by subjects like Java, HTML, DBMS, and more.
It is an Scripting language provided by Microsoft.We can say tat it is an lightweight edition of the Visual Basic(It is an Microsoft,s programming language).
It\'s functionality is dependent upon either ASP engine or windows scripting host.VBScript is only supported by internet explorer.
We use scripting language like VBScript and JavaScript as the extension of HTML language.Only internet explorer read the VBScript and its has a work to read Script with whole content of an web page and to excute them.
These are use as an client side scripting language.
Variant are the single datatype(Kind of data that we store in variable.Datatype may be a character data,string data,number data, boolean data and byte data.) that we used in VBScript.
Using ReDim statement we can change the size of an array in VBScript.I have given you example how to use ReDim.
Example:
Suppose you declare an array Dim Clients(50) Now if you want to change the size of client than you can perform this task with the help of ReDim Like that:
ReDim Customers(70)
VBScript is much differ from Visual Basic.I have given you some important difference b/w them.
- Both VBScript and VBScript are compiled in different way.
- Internet explorer support VBScript on your PC and also we can create web pages using VBScript.
Where in case to run Visual Basic you need some like text editor,ActiveX,Control Pad and Web Browser.
Some information about Dim,public and Private statements .
When we declare private statement variable than these variable are available only in that script in which they are declared.
When we declare public statement variable than it will be available for all procedures of all scripts.
When we declare Dim statement variable at the script level are available for all procedures of all scripts.Where as at the procedure level variables are available only in procedure.
VBScript is supported by platform.These are Windows 95,Windows NT,Windows(16 bits),Unix Solaris.
Generally scope of the variable means we can set an variable can access in whole function or it only access by its local instance. Because of score of variable we can say variable are of two types Local and Global variables.
I have explain this with an example.
<script> Dim name Sub cmdclickme_OnClick Dim age End Sub </script>
In this we example we declare variable \'name\' outside the sub procedure. So, \'name\' variable is worked as global variable it can access by all procedure in all script of web page.But we declare \'age\' variable inside the sub procedure. So, age variable only accessed with in the sub procedure. Than we can say that \'age\' is an local variable.
When we want to insert any script into HTML page than we used <script>tag and use type attribute to define what scripting language we used.
Example:<script type=\"text/vbscript\">
I have given you example in which I used VBScript with HTML document.
Example:<html>
<head>
</head>
<body>
<script type=\"text/vbscript\">
document.write(\"This is my first HTML page with VBScript.\")
</script>
</body>
</html>
Output:This is my first HTML page with VBScript.
We used Script into the web pages in two ways. First we can set script to perform their specific task when web page will loaded.
Second is that script will perform their associated task when used click or trigger an event.
When we insert script in the head section: Script of head is executed when they are called or when an event is trigger in head section.
Example:<html>
<head>
<script type=\"text/vbscript\">
Write some statements here
</script>
</head>
When we insert script in the body section: In this only those script are executed that are placed in body section.
Example:<html>
<head>
</head>
<body>
<script type=\"text/vbscript\">
Write some statements here
</script>
</body>
When we insert script in both body and head section: You can insert script in both body and head section together.
Example:<html>
<head>
<script type=\"text/vbscript\">
Write some statements here
</script>
</head>
<body>
<script type=\"text/vbscript\">
Write some statements here
</script>
</body>
We use variable to store information or values. We can change value of variable during the script.In VBScript all variables are type of variant so each variable can store different type of data.
You have to keep some rules in mind when you create any variable.
- Variable name can\'t more than 255 characters.
- Variable name must start with a letter.
- Variable name doesn\'t contain a period(.).
We can declare Dim,Public or Private statement in VBSCript like that.
dim name
name=Give some value
Now,We created a variable named \'name\'.
When you declare variable with statements(Dim, Public or Private). Than we introduce \'option explicit\' statement before declaring the script.
Like:
option explicit
dim name
name=give some value
Example:
name=\"Abhi\"
x=50
Existence period of variable are told as its Lifetime.
When we declare a variable with a unique procedure.Than when this procedure perform associated task and exits than variable holed by this procedure will destroyed.
It may be happen Variable with same name exists with different procedure.Because each variable perform their specific task.These types of variables are called Local variable.
When we created any Array variable than in this a variable can store more than one value.We declare an array variable using parenthesis()
Example:
Here I declare a variable names.
dim names(3)
In this we declare an array variable names that can store only four values.We can assign value to each element of variable llike that,names(0)=\"Abhi\"
names(1)=\"Sudd\"
names(2)=\"Shrish\"
names(3)=\"Jaeleese\"
Now, we can perticular name entry from name variable to any other variable like that,friend=names(2)
In VBScript their are two types of procedure available.They are Sub Procedure and Function Procedure.
Sub Procedure: In this series of statement are closed b/w the Sub and End Sub statements.It may be Sub procedure performs actions without returning any value.We can passed argument when we called this procedure.Their is no mandatory to pass argument b/w the parentheses.
Syntax:Sub firstsub()
Write some statements here
End Sub
\'OR\'
Sub firstsub(arg1,arg2)
Write some statements here
End Sub
Functional Procedure: In this series of statement must enclosed b/w the Function and End Functio statements.When it perform any action may return a value.We can passed arguments when we called the procedure.Their is no mandatory to pass argument b/w the separateness.When we assign value to variable than it returns that value.
Syntax:Function firstfunction()
Write some statements here
firstfunction=give some value
End Function
\'OR\'
Function firstfunction(arg1,arg2)
Write some statements here
firstfunction=give some value
End Function
You can call the function like thatname = name();
And we can returned the stored value like thatmsgbox \"Welcome: \" & name()
To call the Sub procedure by using Call statement. Like thatCall MyProc(argument)
or you can neglect the Call statement,Like thatMyProc argument
Conditional statements that we used in VBScript are given below:
1.if statement
2.if..than..else statement
3.if..than..elseif statement
4.select case statement
if statement: In if statement we execute a statement when some condition is true.
Example:if i=8 Then msgbox \"Welcome\".
This code will execute only one time.
if..then..else statement: Used when we want to execute more than one statement when some condition is true.
Example:if i=8 Then
In the above code we can execute multiple statements when conditon is ture or using else can execute statement the condition is false.Like
msgbox \"Welcome\"
i = i+1
end If
that,if i=8 then
msgbox \"Welcome\"
else
msgbox \"Wait\"
end If
If conditon is true(i=8)it will display Welcome otherwise Wait.
if..then..elseif statement: We can use this type of statements when we want to execute more than one block of code.It can execute more than one statement whenever our condition is true or
false.
Example:if name=\"Abhi\" then
msgbox \"Welcome Abhi!\"
elseif name=\"Jaleese\" then
msgbox \"Welcome Jaleese!\"
elseif name=\"Shrish\" then
msgbox \"Welcome Shrish!\"
else
msgbox \"R4R Welcomes You!\"
end If
select case statements: using select statement we can execute more than one blocks of code.
Example:select case name
case \"Abhi\"
msgbox \"Welcome Abhi!\"
case \"Jaleese\"
msgbox \"Welcome Jaleese!\"
case \"Shrish\"
msgbox \"Welcome Shrish!\"
case Else
msgbox \"R4R Welcomes you!\"
end select
When you want to execute same blocks of code a particular number of times than we use looping.
VBScript provide us four types of looping statements these are:
1.For..Next statement
2.For Each..Next statement
3.Do..Loop statement
4.While..Wend statement
For..Next statement: When you already know about no of repetitions than you used For..Next statement.
Example:
For i=1 to 5
Write some code here
Next
Above program will display output till value of i is 1,2,3,4,5,
We use \'Step\' keyword you want to increase or decrease the value of variable.
Below,When loop repeated it increase the value of three steps each time.
Example:For i=3 To 15 Step 3
Write some code here
Next
Below,When loop repeated it decrease the value of two steps each time.
Example:
For i=15 To 3 Step -3
Write some code here
Next
If you want to exit For..next statement than we have to use Exit For Keyword.
For Each..Next statement: Using this we can execute a block of code for each element of an array.
Example:dim friends(3)
friends(0)=\"Tom\"
friends(1)=\"Jack\"
friends(2)=\"Sam\"
friends(3)=\"Robert\"
For Each i in friends
document.write(i & \"<br />\")
Next
Do..Loop statement: We use this loop when we don\'t how many times loop will executed.And repeat the block of code till is true.Loop will executed at least one time whenever condition is true or false.
Example:
Do While i>14
Write some code here
Loop
If value of i is less than 14 loop doesn\'t executed.
Do
Write some code here
Loop While i>14
Above,loop will executed atleast one time whenever condition is false(when value of i is less than 14.And it will repeated codes till condition is true.
Until Keyword: Using Until,we can check the condition if it is true than code will not executed.
Example:
Do Until i=5
Write some code here
Loop
It will executed until the value of i is 5.
Example:Do
Write some code here
Loop Until i=5
It will execute code at least one time.And further execute until the condition is true(i=5).
We can exit from do..loop statement after using Do exit keyword.
Example:
Do Until i=5
i=i-1
If i<5 Then Exit Do
Loop
Above, loop is executed when i is different from 5 till it greater than 5.
While..Wend statement: We not use this or else use it do..loop statement.
Yes, VBScript can directly run on users system with Windows as OS.I explain with an example: The running of VB Script is by utilizing Windows Script Host environment. In this input enter through GUI(Graphical User Interface) and output receives from Wscript.exe. It can be raised by Cscript.exe from command line.
As per functionality we can say that VB Script acts same to Java Script. But VB Script is only compatible with internet explorer. VB Script act with Document object model. We can use Visual basic script used for server side processing with ASP.
Using Active X technology we give much more functionality to VB Script.VB provide us sub routines, functions, string manipulation, data/time, error handling etc. We can increase the functionality of VB by using language like that ASP.
scrrun.dll (Scripting Runtime library) is an important library which is used for the functioning of Visual basic script. We can improve some functionality like that File management, text operations and file modification features.
We can use ADODB.Stream class as string builder. Because using VBScript string concatenation we can frequent memory allocation features.So,It is very costly.ADODB.Stream class provide us Binary file and memory I/O operation.Using this we can convert bytes into string etc.
We can allow formatting of numbers by using Tristate constants with functions. Tristate functions are used to reflect and represent the values any where in the code.Without defining Tristate constant it can be used with Vb Script.
VBScript support two types of procedures. These are Sub Procedures and Function Procedures The main difference b/w Sub Procedures and Function Procedures are given below: 1.In case of Sub Procedures we write series of VBScript statements inside the Sub and End Sub statement Where as in Function Procedures we write series of VBScript statements inside the Function and End. 2.Sub Procedures does not return any value where as Function Procedures return a value. 3.Procedures has two build-in VB Script functions these are MsgBox and InputBox. Example: If you want to done calculation.Than Using Sub Procedures we can displays the results of a calculation based on that information. Sub ConvertTemp() temp = InputBox("Enter temperature in degrees F.", 1) MsgBox "Temperature is " & Celsius(temp) & " degrees C." End Sub And Using function procedure we performed the calculation using VBScript. Function Celsius(fDegrees) Celsius = (fDegrees - 32) * 5 / 9 End Function
If you want to use Option Explicit in VBScript you should have to declare all variables using the Dim, Private, Public, or ReDim statements. Using Option Explicit to avoid incorrect typing the name of an existing variable or to avoid confusion in code where the scope of the variable is undefined.
Subtypes of data that a Variant data type in VBScript are given below: Byte - Between 0 to 255 String - Character strings Integer - Between -32,768 and 32,767 Long - Between (-2,147,483,648 and 2,147,483,647) Double - Extremely large numbers with decimal points Empty - The value that a variant holds before being used Error - An error number Null - No valid data Single - Large numbers with decimal points Currency- Monetary values Date - Date and time Object - Objects Boolean - True and False
Parametrization is useful when we want to change object's parameters in accordance with a mathematical rule, or data from a file. We can say that Parametrization is the best way to protect your database from SQL injection attacks.
Yes, We can pass optional argument to VBScript functions.We can use optional argument in VBScript by specifying optional keyword.