Академический Документы
Профессиональный Документы
Культура Документы
v)
End sub
A subroutine will not return any value to the calling program
A function procedure is a series of VBS statements enclosed by function
end function statements
Eg: function name(num1, num2)
------------[Exit function]
End function
A function may or may return a value to the calling function
vi)
vii)
viii)
Function can act like a subroutine where as a subroutine cannot act like a
function
If a function or sub-procedures does not have any argument, then it must
be included with an empty set of parenthesis
Sub or function can have 0-n number of arguments and these values are
separated by comma
Set
VFSO -
Create folder
Create Text field
Delete folder
Delete file
Copy folder
Copy file
Move folder var.
Move file
Folder exists
File exists
Drive exists
Drive
(Get drive)
Folder
(Get folder)
File
(Get file)
- Free space
- Total size
- Drive letter
- Path
- drive type
- Available
space
- Size
- Type
- Name
- Path
- Drive
- Date last
accessed
- Date
created
- Date last
modified
- Attributes
- Size
- Type
- Name
- Path
- Drive
- Date last
accessed
- Date
created
- Date last
modified
- Attributes
var.readline
count=count+1
ERROR HANDLING:
Error handling is a process of handling all the run-time errors within a script so that
the control will reach the end of the script. Sometimes we need to ensure that we
provide user friendly messages to the end-users instead of default error messages.
On the above two occasions we need to initiate the error handling within our script.
Error handling in VBS is a two step process:
i)
suppress the run-time error
ii)
capture the error and take appropriate measure
ON ERROR RESUME NEXT:
On error resume next is a statement provided at the beginning of the script to
suppress the default error message.
ERROR OBJECT:
Every object n VBS will have a unique number and name associated to it. We need to
use this error number and display the appropriate user friendly message.
Error object is a default object used to capture the error code and error name.
We have the following methods in error object
i)
error.number: returns the error code number
ii)
error.description: returns the name of the error
iii)
error.clear: returns the error number to zero.
On error resume next
On error resume next
a=10
b=0
c=a/b
vtemp= err.number
if vtemp=11 then
msgbox " denominator cannot be zero"
else
msgbox C
end if
Array- on error resume next
dim varr(2)
varr(0)=10
varr(1)=20
varr(2)=30
vtemp=err.number
if vtemp=9 then
msgbox "array index cannot be greater than VB"
else
msgbox varr(2)
end if
The above scripts using functions
on error resume next
a=10
b=0
c=a/b
vtemp=err.number
call errorhandler (vtemp)
dim varr(2)
varr(0)=10
varr(1)=20
varr(2)=30
vtemp = err.number
call errorhandler (Vtemp)
function errorhandler(vtemp)
if vtemp=11 then
msgbox "denominator cannot be zero"
elseif vtemp=9 then
msgbox "array index out of range"
else
err.clear
end if
end function
EXCEL PROGRAMMING:
Excel object model:
I level:
II Level:
Excel application
> Save as
> Quit
> Work books
- Save
- Close
- Sheets/ work sheets
o Add
o Count
o Name
o Cells (rows, column)
Value
Font
Size
Bold
Color index
I LEVEL:
Set xl=createobject(excel.application)
II LEVEL:
Set wb= xl.workbooks.open(path)
wb.save
wb.close
xl.quit
set wb= nothing
set xl= nothing
write a script to read values from excel and move them in to 2-d arrays
1,1
1,2
1,3
0,0
0,1
0,2
2,1
Hi
2,3
1,0
Hi
1,2
3,1
3,2
Hi
2,0
2,1
Hi
Excel
Cells (2,2)
Cells (3,3)
Arrays
array (1,1)
array (2,2)
(rc-1,cc-1)
(1,1) (0,0)
(2,2) (1,1)
(1,2) (0,1)
Redim rc(rc-1,cc-1)
Note : excel 3 script
Passing the argument:
By ref:
1. passing argument into procedur (Sub or fun)
2. arguemtns for function can be passed in two ways
- by ref (by reference)
- bv val (by value)
by reference: the procedure is passed the address of the argument variable and the
code inside the function can change the variable
by value: the procedure is passed a copy of the avg variable and the code inside
procedure cannot change the original variable value.
10
11