VB Script
It is an Scripting Language
It’s uses and methods are slightly different from visual basic.
Used to develop Web Pages
It is used inside or with HTML tag.
VB Script & Java Script are two scripting language.
Differences Between Visual Basic & VB Script:
Both are developed by Microsoft Corporation.
VB can be called as scripting language used in Microsoft Excel.
VB Script is used with HTML language to design web pages.
Using VB we can develop efficient and useful softwares, but cannot be used in web pages.
Using VB Script we can design web pages but it cannot be used in VB
Using VB we can create or open a file.
But VB Script can be used for this.
VB Script is used by all Internet User.
VB is an institution or its branches and so on used programs.
VB Script avoids confusion in Computer’s memory because it does not save the file in Computer’s memory.
It can be alone in VB.
Using VB Script we cannot run DLL (Dynamic Link Library) and .exe files.
Using VB we can run DLL and exe files.
Using VB Script we can also run Java Applet and ActiveX Control but VB cannot run these.
Reason:
VB Script is used in web pages. Since it is used by all kinds of people there may be any damages can be done to your computers by other users. For this there is need to avoid certain things like DLL in VB Script.
HTML - Static Language
VB Script – Static language to change the HTML is DHTML we use the scripts.
Script is first used for validation.
Script:
A script is a particular syntax used to execute commands of a computer.
Programming composed for components from a particular scripting language is referred to as a script.
Web Server:
IIS - Internet Infromation Server
PWS - Personal Web Server
JWS - Java Web Server
Editor - Notepad, Dos Editor, Ms-Word
Notepad is largely used.
VB Script should be inserted inside the body tag.
<body>
Prog:
<html>
<head>
<title> VB Script Example </title>
</head>
<body>
<script language = “vbscript”>
“Welcome to my first vbscript program”
</script>
</body>
</html>
<script language = “VBScript”> àStart tag
</script> àend tag
2. Basic Components for Writing VB Script Program:
1. Program is made up of several statements.
2. Statemnts are made up of commands
Commands à Keys to order computer.
Eg. LET, PRINT, END
Some other components are
1. Variable
2. Constant
3. Operators
4. Commands & Statements
5. Functions
Variable:
Datas are structural and functional unit of a program.
Data cannot be used directly it should be stored in a variable.
A = 10
Variable Constant
Variable – value can change at any time.
Constant – Doesnot change.
Variable A = 10 Constant
A = 200
A = 30
Variable are used to store the values in the harddisk (storage location) and are helpful in writing a program.
Variable length can range upto 255 characters.
Average age of the student = 20
Variable length = 22
Eg:
Average age of the student – avgagestu
Note:
First letter should not be a number
It should be an alphabet
1avg = 20 à Wrong
a1 = 10 à Right
1a = 10 à Wrong
We can use underscore
Avg _ age _ stu àright
Avg – age- stu à wrong dot is not allowed
Avg age stu à Space also not allowed
Variable Type:
In VB Script there is only one variable type
Ie. Variant type
Variant type depends on the data type.
Data Type Description
1. Integer 1567
2. Long 157897
3. Byte Contains Binary Digits
eg. 10110 (Range 0 to255)
4. Single Floating – point number
(decimal upto 4 digits)
eg. 1.567
5. Double Floating point having
more than 4 digits
eg. 1.567897
6. Date Contains no’s that
represent date
eg. December 31, 9999
7. String Store numbers&characters
(upto 2 billion characters
in length contains objects
8. Object Contains Objects
9. Error Contains error number
In order to find datatype we can use the function typename.
A=10
Type name (a)
Msgbox typename(a)
Default typename is double à For decimal numbers
Default typename is Integer à For binary numbers
Default typename is Date à For string
<html>
<head>
<title> CSC private Ltd</title>
<body>
<script language = “VbScript”>
a=200
msgbox typename(a)
a=4858943
msgbox typename(a)
a=200.5
msgbox typename(a)
a=1.1
msgbox typename(csng(a))
a=”compcare”
msgbox typename(a)
c=true
msgbox typename( c )
d=1
msgbox typename(cbyte(d))
y=”2/2/90 ”
msgbox typename(datevalue(y))
dim p
msgbox typename(p)
k=null
msgbox typename(k)
</script>
</body>
</html>
Dim p = Result Empty
K =NULL =Result NULL
Checking the variable type
1. isarray() Checks whether the given one is
array or not
2. isdate() Checks whethers the given one is
date or not
3. isempty() Checks whether the given one is
empty or not
4. iserror() Checks whether the given variable is error or not
5. isnumeric() Given variable Is numeric or not
<html>
<head>
<title> CSC private Ltd </title?
</head>
<body>
<Script language = “VbScript”>
a=200
if(isnumeric(a)) then
msgbox (“The variable holds numeric value …”)
else
msgbox (“The variable does not hold numeric value …”)
end if
msgbox “The variable type is…”&typename(a)
b=”compcare”
if(isnumeric(b)) then
msgbox (“The variable holds numeric value …”)
else
msgbox (“The variable does not holds numeric value …”)
end if
msgbox “The variable type is …” & typename(b)
</script>
</body>
</html>
Note:
If (condition) then
Statement à True
Else
Statement à False
Convertion Function:
Eg:
A = “200”
B = “700”
C=a+b
C=”200” + “700”
C=cint(a) + b
C=200 + 700
C=900
1. Asc() Gives ASCII value for a character
2. Chr() Gives character for a ASCII code given
3. CBool() Gives corresponding boolean value
4. CByte() Gives byte value
5. CDate() Returns datevalue for corresponding value
6. CDbl() Gives corresponding double value
7. CInt() Gives integer value
8. CLng() Will return long integer value
9. CSng() Will return single value
10. CStr() Converts given one into string
11. CvErr() Gives Error
12. Sgn() Gives sign value
13. Str() Gives string value
14. Val() String number
15. Date Value() String date value
16. Time Value() String time value
17. Fix() Decimal – whole number part only
18. Int() Decimal – Integer
<html>
<head>
<title> CSC private Ltd </title>
</head>
<body>
<script language=”vbscript”>
a=67
document.write “The given ascii code is … &a
document.write “<br>”
document.write “The corresponding character is …”&chr(a)
document.write ”<br>”
b=”A”
document.write “The given character is …” &b
document.write “<br>”
document.write “The corresponding ascii value is … & asc(b)
document.write “<br>”
c =+ 12
document.write “The given number is …. &c
document.write “<br>”
document.write “The corresponding boolean character is … & cbool ( c )
document.write “<br>”
c=0
document.write “The given no is … “ &c
document.write “<br>”
document.write “The corresponding boolean character is …” & cbool ( c )
document.write “<br>”
d=-8.65
document.write “The given no is … “ &d
document.write “<br>”
document.write “The corresponding fix value is … “ &fix(d)
document.write “<br>”
document.write “The corresponding int value is … “ &int(d)
document.write “<br>”
d= “12/01/03 ”
document.write “The given number is … &d
document.write “<br>”
document.write “The corresponding date value is … & datevalue(d)
document.write “<br>”
d= “11:40:30 ”
document.write “The given no is …”&d
document.write “<br>”
document.write “The corresponding time value is …” &timevalue(d)
document.write “<br>”
d= -90
document.write “The given no is …” &d
document.write “<br>”
document.write “The corresponding sign value is …”&sgn(d)
document.write “<br>”
</script>
</body>
</html>
Constant
Values doesnot change at any instant
There are number of constants.
A=10 -> Integer Constant
B=1.1 -> Floating Constant
C=”Compare” -> String Constant
Operators
Used for some calculation
It joins the operands
Operators
C=a+10-3/2 Expression
Operands
Operands may be a variable or constants
Operands + Operators -> Expressions
When expression is made to match with a variable then it is called statements
Classifications of operators:
1. Arithmetic Operator
2. Comparison Operator
3. Logical Operator
Arithmetic Operators:
+ = Addition
- = Subtraction
* = Multiplication
/ = Decimal division
\ = Integer division
^ = Exponentation (power)
mod = Remainder
& = Concatenation (Joins two strings)
Comparison Operator:
Used to compare two operands
= = Equal to
< > = In Equality
< = Less than
> = Greater than
<= = Less than or equal to
>= = Greater than or equal to
is = Objective equivalence
(Compare two objects)
eg:
if (100 > 20) then
if (a=b) then
Logical Operator:
We use relational operators to compare two operands logical operators are used to compare more than two operands.
Eg:
100 > 20 AND 10 > 3
Operator Description/Use
NOT Negation
AND Logical AND
OR Logical OR
XOR Exclusive OR
Equ Equivalence
Imp Implies
And:
If all the condition is true then the result is also true.
If any one condition is false then the result is also false.
Eg:
If (100>20) AND (100<5) Then
True and false = false
If(200 > 100) AND (200>20) then
True and True = True
And Operator
First Expression Second Expression Third Expres
True True True
True False False
False True False
False False False
Or Operator
If any one of the given expression is true then whole expression is said to be true
Eg:
If (100>20) or (100>300) then
True or false = true
The table for or operators
First Expression Second Expression Third Expres
True True True
True False True
False True True
False False False
Not Operator
If the given expression is true result is false and if the given expression is false result is true
Eg:
If(not(age<40) then
Expresion Result
True False
False True
Function:
The functions can be classified as
1. Date and time function
2. Numeric function
3. String function
Date and Time Functions:
1. Date() 6. Time()
2. Day() 7. Minute()
3. Month() 8. Hour()
4. Year() 9. Second()
5. Weekday() 10. Now()
<html>
<head>
<title> Time Program </title>
</head>
<body>
<script language = “vbscript”>
document.write “Current date is…” &date()
document.write “<br>”
document.write “Current day is…” &day(date())
document.write “<br>”
document.write “Current month is…” &month(date())
document.write “<br>”
document.write “Current year is …”&year(date())
document.write “<br>”
document.write “Current week day is …” &weekday(date())
document.write “<br>”
document.write “Current time is …”&time()
document.write “<br>”
document.write “Current minute is …” &minute(time())
document.write “<br>”
document.write “Current hour is…” &hour(time())
document.write “<br>”
document.write “Day of the given date 11/12/90 …” & day(datevalue(“11/12/90 ”))
document.write “<br>”
document.write “Second of the given time 10:12:45 is …” & second (time value(“10:12:45 ”)
</script>
</body>
</html>
Function Description / Uses
Date() Returns current date
Time() Returns current time
Now() Returns current date and time
Datevalue string date to date
Weekday weekly
Numeric Functions:
They are
1. abs()
absolute value
negative -> positive
eg: y=abs(-45)
y=45
2. sgn() => gives the sign value
eg: y=sgn(4) p=sign(-4)
y=1 p=-1
3. Sqr()
Square root function
P= sqr(4)
P=2
4. Fix()
Gives only the whole number value leaves the decimal
Y=fix(11.56)
Y=11
5. Int() Integer
It rounds the decimal places
Eg: y=int(11.89) x=int(11.30)
X=12 x=11
6. exp() Power function
x=exp(2)
x=7.3890
7. log() function
gives log value
y=log(5)
y=1.6094
8. Rnd
Gives a decimal no inbetwen 0 and 1
X=rnd()
X=0.00718
If RND is used another time it gives new value
eg: 0.01793
9. sin() sine
gives the sine value
y=sin(0)
y=0
10. cos() function
gives cosine value
y=cos(0)
y=1
11. atn() arc tangent value
y=atn(0)
y=1
12. tan() givens tangent value
y=tan(0)
y=1
<html>
<head>
<title> Numeric function</title>
</head>
<body>
<script language = “vbscript”>
document.write “Absolute value of -45 is … “&
abs(-45)
document.write “<br>”
document.write “Sign value of -4 is … & sgn (-4)
document.write “<br>”
x=-9.67
document.write “Fix of -9.67 is …” &fix(x)
document.write “<br>”
document.write “Square root of 16 is …” &sqr(16)
document.write “<br>”
document.write “Random no is …”&rnd()
document.write “<br>”
document.write “Sine value of 0 os … &sin(0)
document.write “<br>”
document.write “Exponential of 2 is …” &exp(2)
document.write “<br>”
</script>
</body>
</html>
String Function
Used to handle characters
1. Asc
gives ASCII value
y = “c”
x=asc(y)
=99
A = 65 a = 97
Z = 90 z = 122
2. Chr() function
Changes ASCII code to character
b = chr(98)
B = b
3. Len() function
It calculates the length of the given string i.e. no of letters in the given string.
X=len(“compare”)
X=8
4. Val() function
Changes character to value for the doing calculation
P = “123”
Y = val(p)
Y = 123 “123” à 123
String Value
5. Lcase() function
Changes the given characters into small letters (Lower Case Letters)
Y = “COMPARE”
P = lcase(y)
=compare
6. Ucase() function
Changes the given characters into capital letter (upper case letters)
P = “compare”
Y = Ucase(p)
=COMPCARE
7. Left() function
It returns characters from the left – hand side of string
Y = “COMPCARE”
P=left(y,3)
=com
First argument is the string from which you are returning characters
Length is the number of characters to return
8. Right() function
p = “COMPARE”
q = right (p,3)
=ARE
9. Mid() function
It returns characters from any part of a string
P = “COMPCARE”
Q = mid (p,3,2)
=MP
10. Mid (p,3,2)
11. Trim() function
y = “ Compare “
x=trim(y)
= compare
12. Ltrim() function
y = “ Compare”
p=ltrim(y)
f=len(p)
f=8
13. Rtrim() function
y = “compare “
p=rtrim(y)
x=len(p)
x=8
14. Str() function
number à string
y=123
p=str(y)
p=”123”
15. String() function
Repeat string upto length specified
Y=string (3, ‘a’)
= aaa
16. Strcomp() function
strcomp (“cat”, “ate”) or strcomp(“cat”, “ant”)
99 - 92
2
cat>ant
Compaison is based on ascii value
<html>
<head>
<title> String function </title>
</head>
<body>
<script language = “vbscript”>
document.write “ltrim of string is …”<rim
(“ Compare”)
document.write “<br>”
if(strcomp(“comp”,”apple”)>0 then
document.write “The first string is big …”
else if(strcomp(“comp”,”apple”)<0 then
document.write “The second string is big …. &”apple”
else if(strcomp(“comp”,”apple”)=0 then
document.write “Both the strings are equal”
endif
</script>
</body>
</html>
Statements
There are two types of statement in vbscript
1. Branching Statements
2. Looping Statements
To input data – inputbox
To get data – outputbox
Inputbox can divided into three
1. Title of the input box
2. Prompt message
3. Default text
Title of the input box gives title
Prompt message – what do to type in the input box
Default text – value getting place
Syntax:
Inputbox (prompt [,[title][,default]])
Inputbox (“Enter your name”, “sample inputbox” “type the name here”)
Prompt is more important in inputbox
Other two are default type
<html>
<head>
<title> Sample inputbox </title>
</head>
<body>
<script language = “vbscript”>
y=inputbox(“Enter your name…”,”sample inputbox”,”Type the name here …”)
docucment.write “The given name ius … “&y
</script>
</body>
</html>
Message box:
It displays the result
Syntax
Msgbox(msg,[[type],[title]])
Msg – place to give message
Title – gives heading for the message box
Type – it determines the type of buttons and no of buttons
Function | Description / Uses |
0 1 2 3 4 5 | Ok button Ok and cancel buttons Abort, Retry and Ignore buttons Yes, No and Cancel buttons Yes, No buttons Retry and Cancel Button |
Eg:
Msgbox (“The name is”, 0, “Sample msgbox”)
Msgbox (“The name is”, 1, “Sample msgbox”)
Msgbox (“The name is”, 3, “Sample msgbox”)
Msgbox (“The name is”, 5, “Sample msgbox”)
Before the message in message box we can insert some special mark
Number | Special Symbols |
16 32 48 64 | Stop Icon Question Icon Exclamation Icon Information Icon |
Eg:
Msgbox (“The name is”, 0+16, “sample message box”)
Msgbox (“The name is”, 0+48, “sample message box”)
Msgbox (“The name is”, 0+64, “sample message box”)
Sample message box:
Msgbox (“Entitled name is …”)
Eg:
<html>
<head>
<title>Sample message boxes </title>
</head>
<body>
<script language=”vbscript”>
msgbox (“The name is …”, 3, “sample msgbox”)
msgbox (“The name is …”, 0+48, “sample msgbox”)
</script>
</body>
</html>
Uses of message box:
If msgbox value is getted in a variable then we can do lot of calculation using them.
Eg:
OK button – 1
Cancel button – 2
Code | Button |
1 2 3 4 5 6 7 | OK Cancel Abort Retry Ignore Yes No |
<html>
<head>
<title>Msgbox calculation</title>
</head>
<body>
<script language = “vbscript”>
a=inputbox (“Enter the first no …”,”sample program”,”type the first no here”)
b=inputbox(“Enter the second no …”,”sample program:,”type the secod no here”)
ans=msgbox(“The resultant value is … [press yes to find addition] [press no to find subtraction]”, 4, “output”]
if (ans=6) then
c=int(a) + int(b)
document.write “The addition is …” &c
else if(ans=7) then
c=int(a) – int(b)
document.write “The subtraction is …”&c
endif
</script>
</body>
</html>
1. Branching statements
2. Looping statenebts
Branching:
If the given condition is satisfied it runs some statements if not it runs other.
There are about three types
1. Simple if then else
2. Else if ladder
3. Nested if else
Simple if:
It checks only one condition if it is true, the statements after then will be executed.
Syntax:
If (condition1) then
Statements
Else
Statements
Endif
Statements
<html>
<head>
<title>Compcare software Limited</title>
</head>
<body>
<script language = “vbscript”>
a=inputbox (“Enter a no …”,”Simple if program”, “Type the no here”)
if(a>0)then
document.write “The given no is positive …”&a
else
document.write “The given no is negative …”&a
endif
</script>
</body>
</html>
else if ladder
More than one statement will be executed.
Syntax:
If(coondition1)then
Statements
Else if(condition2) then
Statements
Else if(condition3) then
Statements
Endif
If condition1 is true the statement after then will be executed if it is false the statement after elseif will be executed like this it goes on.
<html>
<head>
<title> else if ladder program </title>
</head>
<body>
<script language = “vbscript”>
name=inputbox (“Enter the name …”,”elseif ladder program”,”Enter the name here …”)
code=inputbox (“Enter the roll no …”,elseif ladder program”, Enter the rollno here …”)
mark1=inputbox(“Enter the mark1 …”, elseif ladder
program, “Enter the mark1 here …”)
mark2=inputbox(“Enter the mark2 …”, elseif ladder
program, “Enter the mark2 here …”)
tot = mark1+mark2
avg = tot/2
if(avg>=80 and avg<=100) then
g=”excellent”
else if(avg>=60 and avg<80) then
g=”very good”
else if(avg<=600)then
g=”good”
endif
document.write “The name of the student is …”&name
document.write “The code of the student is …”&code
document.write “Total is …”&tot
document.write “The average is… “&avg
document.write “The grade is …”&g
</script>
</body>
</html>
Nested if else
Compound if statement
Syntax:
If(condition 1)then
If(condition 2)then
Statements
Else
Statements
Endif
Else if(condition 3)then
If(condition 2)then
Statements
Else
Statements
Endif
Endif
Looping statements
1. Do.. while
2. Do.. Until
3. While.. Wend
4. For.. Next
The basic for these looping structure
1. Intial value
2. Final value
3. Condition Checking
4. Increment or Decremnt
1. Do.. While
It executes as long as the condition (remains) becomes false
Syntax:
Initial value
Dowhile <condition>
Statements
Increment/decrement
Statements
<html>
<body>
<script language = “vbscript”>
f=1
i=1
do while(i<=3)
f=f*i
i=i+1
loop
document.write “The factorial value of 3 is…” &f
</script>
</body>
</html>
Initial value =1
Initial value = 3
2. Do..Until:
It executes as long as condition becomes true
Syntax:
Intial value
Do until <condition>
Statements
Increment/decrement
Statements
If the condition false it will run
<html>
<body>
<script language = “vbscript”>
i=1
do until(i>3)
document.write “Murali” &”<br>”
i=i+1
loop
</script>
</body>
</html>
3. While..Wend:
It is similar to dowhile. It executes or run the program until the condition becomes false using this we can design and run some statements according to our needs.
Syntax:
While<condition>
Statements
Increment/decrement
Wend
Statements
<html>
<body>
<script language = “vbscript”>
s=0
i=1
while(i<=3)
s=s+i
i=i+1
wend
document.write “The sum of the series is …”&s&”<br>”
</script>
</body>
</html>
4. For..Next:
The for statements is one of the most commonly used loop. The statement include expression that specifies an initial value for an index, another expression that determines whether the loop is to be executed or not
1. Initial value
2. Final value
Syntax:
For variable = initial value to final value step step value
Statements
Nest
Statements
If step value is positive – the value of the variable increases
If step value is negative – the value of the variable decreases
<html>
<body>
<script language = “vbscript”>
for i=2 to 6 step 2
document.write I &”<br>”
next
</script>
</body>
</html>
Forward and backward loop:
If initial value is les than that of final value and if the value of the variable increases it is said to forward loop.
If initial value is greater than that of final value and if variable value decreases inside the loop that is said to be backward loop.
Increment loop:
I=1
While(i<=5)
Document.write i&”<br>”
I=i+1
Wend
Decrement loop:
I=5
Dowhile (i>=1)
Document.write i&”<br>”
I=i-1
I=i+1 – forward loop
I=i-1 – backward loop
Forward:
I=1
Dowhile(I<=3)
I=i+1
I=1
While(i<=3)
I=i+1
Wend
I=1
Dountil(i>=3)
I=i+1
For i=1 to 3 step 3
-
-
-
Next
Backward:
I=3
Dowhile(I>=1)
I=i-1
I=1
While(i>=1)
I=i-1
Wend
I=1
Dountil(i<=1)
I=i-1
For i=3 to 1 step -1
-
-
-
Next
Select Case
Using this we can select a particular item and run program on the basic of it.
Syntax:
Select case <variable>
Case value1
Statements
Case value2
Statements
Case else
Statement
End select
Statements
<html>
<body>
<script language = “vbscript”>
a1=10
b1=20
ch=inputbox(“Enter the choice: type a for +, s for -, m for *, d for /”)
select case ch
case “a”
c=a1+b1
case “s”
c=a1-b1
case “m”
c=a1*b1
case else
c=a1/b1
end select
document.write “The solution is…”&c
</script>
</body>
</html>
Function & procedure
Using these we can split a large programs into a sampler one so that we can understand easily and also we can find out errors in our program.
Procedure:
Syntax:
Sub<procedure name(arguments)>
Statements
End sub
Call<procedure name(arguments)>
Option explicit for all of the variables used in vb declared explicitly
1. Sub should be ended with endsub
2. A name has to be given to the procedure eg. Sub adition
3. Arguments – variables
If values impressed from the main program to the procedures it can be stored in the arguments. It is not necessary at all times.
if more than one value is passed from main program to procedures we have to give use this
sub addition(a,b)
sub is used to declare a statement that form a subroutine.
If no arguments are passed
End sub confirms the ending
Procedures should be called
Call addition(a,b) or call addition()
This is the main part of the program
The no. of values passed from main program to procedure should be same.
Eg:
Call addition (a,b,c)
Sub addition (a,b,c)
Sub addition (a,b)
The program doesnot run properly
Call addition (a,b)
Sub addition (x,y)
C=x+y
End sub
Function:
1. It is used to minimize the repetition work .
2. Used to declare a set of statements that formed the body of function.
Statements:
There are 7 types of statements
1.Call statement:
It transfers control to subroutines or function
Syntax:
Eg:
Call <function name>
Call sum
2. const:
It declares a constant that can be used in place of literal (constant) value
Syntax:
Const <variable name> = expression
A=10
3. Dim:
It declares the variables and allocate the memory
Syntax:
Dim variable name[[upperbound],[lowerbound]] array
Or
Dim <var name>
Eg:
Dim a
Dim arr(8,2)
4. Set statement:
This is used to assign an object reference to variable of property
5. Option Explicit
6
7. Su. Function b
Function:
Syntax:
Variable = <function name(arguments)>
Function <function name(argument)>
Statements
Function name=resultant variable
End function
Function program should be between function end function
Give name to the function
Eg. Function fact()
Arguments can be passed if more than one argument is passed, they should be separated by commas
Function fact(a,b)
Function program should be given between <function name (argument)> and end function
It should be called before or after the written function program
Variable = function name(arguments)
Eg. Y=fact(n) -> main program
If value is passed to function from main program we have call like this
Y=fact(n)
If no value is passed
Y=fact()
<html>
<body>
<script language=”vbscript”>
c=summation()
document.write “The addition is …”&c&”<br>”
-------------------------
function summation()
a1=inputbox(“Enter the first no…”)
b1=inputbox(“Enter the second no…”)
summation = int(a1)+int(b1)
endfunction
</script>
</body>
</html>
<html>
<body>
<script language=”vbscript”>
a1=inputbox(“Enter the first no…”)
a2=inputbox(“Enter the second no…”)
c=addition(a1,b1)
d=multiplication(a1,b1)
document.write ”Addition is…”&c&”<br>”
document.write “Multiplication is…”&d&”<br>”
function addition()
addition = int(a1)+int(b1)
end function
function multiplication()
multiplication = int(a1)*int(b1)
end function
</script>
</body>
</html>
Arrays and Matrix:
Using looping structure we can minimize the no of variables in a program but variables does not have values at all places.
Without looping structures we have to use 100 variables for input 100 numbers.
To avoid these two difficulties arrays are used.
Arrays means storing large or more datas in a single memory space
A1 a2 a3 a4 a5
5 10 13 14 17
A(0) | A(1) | A(2) | A(3) | A(4) |
5 | 10 | 13 | 14 | 17 |
Here a(0), a(1), a(2), a(3) &(4) are array elements
Array elements stored in memory sequentially
Array elements are considered as a single variable
If we give a(5)
A array allots five memory spaces
First element in array is (subscript) 0
Serial no for last element is (subscript) 4
It is an one dimensional array
Two dimensional arrays:
5 | 3 | 2 |
7 | 5 | 8 |
5 | 6 | 7 |
A(3,3)
3-rows
3-columns
A(0,0) | A(0,1) | A(0,2) |
A(1,0) | A(1,1) | A(1,2) |
A(2,0) | A(2,1) | A(2,2) |
<html>
<body>
<script language = “vbscript”>
dim itemarray(3)
item array(0)=”bread”
item array(1)=”cakes”
item array(2)=”honey”
item array(3)=”biscuits”
msgbox “The value of the counter is “&itemarray(2)
</script>
</body>
</html>
<html>
<body>
<script language=”vbscript”>
my array(1,0)=”juliat”
my array(1,1)=94
my array(2,0)=”raju”
my array(2,1)=39
my array(3,0)=”ganesh”
my array(3,1)=67
msgbox “The code of “&my array(3,0)&”is”&my array(3,1)
</script>
</body>
</html>
increasing array elements
<script language = “vbscript”>
dim itemarray()
redim itemarray(4)
item array(3)=”choclates”
msgbox itemarray(3)
redim itemarray(6)
msgbox itemarray(6)
</script>
</body>
</html>
Redim is used to increase the size of array element.
No comments:
Post a Comment