‘ 1.how to open browser in vb script
set ie=createobject(“internetexplorer.application”)
ie.navigate(“http://www.google.co.in/”)
ie.visible=true
set ie = nothing
‘ 2.Why to use option explicit in vb script
‘If we declare variables with some values and while using if we use (spell mistake) then user can’t know
‘ putting option explicit is useful there
‘ Example starts here
option explicit
dim abcd
abcd=20
msgbox abcd
dim bcde
bcde=30
msgbox bcdef
’3.how to open a file .What is the perpose of true and false mode there
‘How to read from file and write into the file
set files = createobject(“scripting.filesystemobject”)
set obj1=files.opentextfile(“d:\file2.txt”,2,true) ‘ true uses for ceating txt file
set obj2=files.opentextfile(“d:\file2.txt”,1,false) ‘ false will not create any file
obj1.writeline(“write this line into file”)
str=obj2.readline
msgbox str
set files=nothing
’4.if else for do while select in vb script
i=5
j=6
if i>j then
msgbox i
elseif i<j then
msgbox j
else
msgbox “nothing”
end if
for i=5 to 10 step 2
msgbox i
next
do while i<15
msgbox i
i=i+3
loop
mycase=”gitam”
select case mycase
case “abcd”
msgbox “abcd”
case mycase
msgbox mycase
case else
msgbox “wrong”
end select
’5.how to write functions and sub in vb script
function add(a,b)
sum=a+b
add=sum
end function
s=add(6,8)
msgbox s
sub add2(x,y)
sum=x+y
msgbox sum
end sub
call add2(6,8)
’6 what is variant in vb script
variant is the only datatype in vb script.There are many subtypes under variant.
They are Empty,Null,Boolean,Byte,Integer,Currency,Long,Single,Double,Date ,String,Object,Error
‘ 7 .how to open excel in vb script
set xl=createobject(“excel.application”)
set wb=xl.workbooks.open(“d:/sample.xls”)
set ws=wb.worksheets(1)
ws.cells(3,4)=”welcome”
wb.save
wb.close
set wb=nothing
set ws=nothing
set xl=nothing
‘ 8.difference between dim,public and private variables in vb script
‘ Use of dim ,private and public variables in vb script
function first
dim a
a=20
msgbox a ‘ 20 displays
end function
first
msgbox a ‘ this gives empty value
‘ so dim variables are not public if we use within function
dim b
b=30
function second
msgbox b ‘ 30 displays
end function
second
‘ if we declare dim variables outside the function then it will act as public
class myclas
public c
private d
dim e
sub mysub
c=40
d=50
e=60
msgbox “public : “&c&” private :”&d&”dim :”&e
end sub
end class
set obj=new myclas
obj.mysub
msgbox obj.c
‘msgbox obj.d ‘it won’t allow to display private variables
msgbox obj.e
Recent Comments