Sunday, April 17, 2011

some examples filesystemobject

Option explicit
Dim mseo,wbo,wso,x,y,z,r,i
Set mseo= createobject("excel.application")
mseo.Visible=true
Set wbo=mseo.Workbooks.Open("c:\mydata.xls",2,true)
Set wso=wbo.Worksheets("sheet1")
r=wso.usedrange.rows.count
For i=1 to r step 1
x=wso.cells(i,1)
y=wso.cells(i,2)
z=eval(x)
If y=z Then
    wso.cells(i,3)="passed"
    else
    wso.cells(i,3)="failed"
    End If
    Next
    wbo.Save
    mseo.Quit
=================================================================
fsdfsOption explicit
Dim fso,fo,f,fc,sf
Set fso=createobject("scripting.filesystemobject")
Set fo=fso.GetFolder("c:\program files")
print "files are"
print "------"
Set fc=fo.files
For each f in fc
    print f.name
    Next
    print"sub folders are:"
    print"----"
    Set sf=fo.subfolders
    For each f in sf
        print f.name
    Next
=================================================================
Option explicit
Dim fso,f,x
Set fso=createobject("scripting.filesystemobject")
Set f=fso.OpenTextFile("c:\textfile.txt",2,true)
f.Write"hello world"
f.Close
Set f=fso.OpenTextFile("\textfile.txt",1)
x=f.ReadLine
msgbox x
f.Close
Set fso= nothing
Set f=nothing
====================================================================
Option explicit
Dim xmlo,root,childs,x,y,i
Set xmlo=xmlutil.CreateXMLFromFile("c:/temp4.xml")
Set root=xmlo.GetRootElement
Set childs=root.ChildElementsByPath("ctemp/temp1")
For i=1 to childs.Count step 1
     x=childs.Item(i).Value
     y=childs.Item(i).Attributes.Item(1).Value
     print x&"in"&y
Next
Set childs=nothing
Set root=nothing
Set xmlo=nothing
==================================================================

Option explicit
Dim xmlo,root,childs,x,i,y
Set xmlo=xmlutil.CreateXMLFromFile("c:/emp.xml")
Set root=xmlo.GetRootElement
Set childs=root.ChildElementsByPath("employee")
For i=1 to childs.Count step 1
     x=childs.Item(i).ChildElementsByPath("name").Item(1).Value
     y=childs.Item(i).ChildElementsByPath("did").Item(1).Value
    print x&"indept no"&y
Next
Set childs=nothing
Set root=nothing
Set xmlo=nothing
=========================================================
Option explicit
Dim xmlo,root,childs,x,i
Set xmlo=xmlutil.CreateXMLFromFile("c:/emp.xml")
Set root=xmlo.GetRootElement
Set childs=root.ChildElementsByPath("employee/name")
For i=1 to childs.Count step 1
     x=childs.Item(i).Value
     print x
Next
Set childs=nothing
Set root=nothing
Set xmlo=nothing
============================================================
Option explicit
Dim x,n,i
print "hai testers"
n=datatable.getsheet(1).GetRowCount
For i=1 to n step 1
    datatable.GetSheet(1).setCurrentRow(i)
    x=datatable.Value("name",1)
    print x
Next
============================================================
Option explicit
Dim exo,wbo,wso,i
Set exo=createobject("Excel.Application")
exo.Visible=true
Set wbo=exo.Workbooks.Add
Set wso=wbo.Worksheets("sheet1")
For i=1 to 56 step 1
    wso.cells(i,1).font.colorindex=i
        wso.cells(i,1)=i
Next
wbo.Saveas("c:\colors1.xls")
exo.Quit
Set wso=nothing
Set wbo=nothing
Set exo=nothing
=============================================================

Option explicit
Dim con,rs,x,y
Set con=createobject("ADODB.connection")
con.Open "testing"
Set rs=createobject("ADODB.RecordSet")
rs.Open "select AT_ID,AT_USER from td.ALERT",con
While rs.EOF<>True
    x=rs.Fields("AT_ID").Value
    y=rs.Fields("AT_USER").Value
print y&" have "&x&"as id"
rs.MoveNext
Wend

con.Close
==============================================================
Option explicit
Dim odesc,list,i
Set odesc= description.Create
odesc("micclass").value="image"
invokeapplication "C:\Program Files\Internet Explorer\iexplore.exe"
browser("title:=about:blank").Navigate "http://localhost:8080/mtours/servlet/com.mercurytours.servlet.WelcomeServlet"
set list=browser("title:=Welcome: Mercury Tours").page("title:=Welcome: Mercury Tours").ChildObjects(odesc)
For i=0 to list.count-1 step 1
    If list(i).object.complete= true Then
       reporter.ReportEvent micPass,"image test","image completely loaded"
       else
           reporter.ReportEvent micFail,"image test","image not completely loaded"

    End If
Next
browser("title:=.*").Close
Set list=nothing
Set odesc=nothing
========================================================
Option explicit
Dim x,y
x=" admin"
y="admin"
invokeapplication "c:\programflies\internetExplorer\iexplore.exe"
browser("title:=about:blank").Navigate"http://newtours.demoaut.com/"
With browser("title:=welcome:mercuryTours")
with.page(" title:=welcome:mercuryTours")
.webedit("name:=user Name").setx
.webedit("name:=password").sety
.image("name:=login").click
End with
End with
If browser("title:=Find a Flight:Mercury tours:").Exist Then
    reporter.ReportEvent Micpass,"logintest","in-correctlogin"
End If
browser("title:=.*").close
===============================================================
Option explicit
Dim odesc,list,i,x,y
Set odesc= description.Create
odesc("micclass").value="image"
invokeapplication "C:\Program Files\Internet Explorer\iexplore.exe"
browser("title:=about:blank").Navigate "http://localhost:8080/mtours/servlet/com.mercurytours.servlet.WelcomeServlet"
set list=browser("title:=Welcome: Mercury Tours").page("title:=Welcome: Mercury Tours").ChildObjects(odesc)
For i=0 to list.count -1 step 1
   x=list(i).getroproperty("name")
   y=list(i).getroproperty("src")
   print x & " image src is " &y
Next
browser("title:=.*").Close
Set list=nothing
Set odesc=nothing
===============================================================
Option explicit
Dim bros,n
Set bros=description.Create
bros("micclass").value="browser"
Set n=desktop.ChildObjects(bros)
msgbox n.count
=============================================================
invokeapplication "C:\Program Files\Internet Explorer\iexplore.exe"
browser("title:=about:blank").Navigate "http://localhost:8080/mtours/servlet/com.mercurytours.servlet.WelcomeServlet"
If browser("title:=Welcome: Mercury Tours").Exist Then
    reporter.ReportEvent micPass,"home page open test","correctly opened"
    browser("title:=.*").Close
    else
    reporter.ReportEvent micFail,"home page open test","incorrectly opened"

End If
===============================================================
Option explicit
Dim con,rs,x,y
Set con=createobject("ADODB.connection")
con.Open "provider=SQLOLEDB;Server=MINDQ10;Database=QualityCenter_Demo_db;Trusted_Connection=yes"
Set rs=createobject("ADODB.RecordSet")
rs.Open "select AT_ID,AT_USER from td.ALERT",con
While rs.EOF<>True
    x=rs.Fields("AT_ID").Value
    y=rs.Fields("AT_USER").Value
print y&" have "&x&"as id"
rs.MoveNext
Wend

con.Close
==========================================================
Option explicit
Dim con
Set con=createobject("ADODB.connection")
con.Open "DSN=QT_Flight32"
con.Execute("update orders set Tickets_Ordered=10 where order_number=5")
con.Close
===========================================================
Dim str
str="suman is a good girl"
msgbox instr(3,str,"is")
=======================================================
Option explicit
Dim exo,wbo,wso,x,y,z,n,i
Set exo=createobject("excel.appliocation")
exo.visible=true
Set wbo=exo.workbooks.open("d:\colm.xls")
Set wso=wbo.worksheets("sheet1")
n=wso.usedrange.rows.count
For i=2 to n step 1
    x=wso.cells(i,1)
    y=wso.cells(i,2)
    z=x+y
    wso.cells(i,3)=z
Next
wbo.save
exo.quit
Set wso=nothing
Set wbo=nothing
Set exo=nothing
====================================================================
Option explicit
dim fso,fo,x
Set fso=createobject("scripting.filesystemobject")
Set fo=fso.OpenTextFile("c:/aaa.txt",1,false) ''''12+12------
While fo.AtEndOfStream<>true
    x=fo.ReadLine
    If eval(x) Then
        print x&"true"
        else
        print x&"fale"
    End If
Wend
fo.Close
Set fo=nothing
Set fso=nothing
===================================================

Option explicit
Dim fso,foo,fs,x,y,i
Set fso=createobject("scripting.filesystemobject")
Set foo=fso.getfolder("C:\flight reservation")
Set fs=foo.files
print "vbs files"
print "*************************"
For each i in fs
    x=i.name
    y=right(x,3)
    If y="vbs" Then
print x
    End If
Next
========================================================
Dim dbcon
Set dbcon=CreateObject("Adodb.Command")
dbcon.provider="microsoft.jet.oledb.4.0"
dbcon.Open"C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Set rs=CreateObject("Adodb.RecordSet")
Set cmd=CreateObject("Adodb.Command")
cmd.ActiveConnection=dbcon
cmd.CommandText="select order_number,customer_name from orders where order_no<=5"
rs.Open=cmd.Execute
Do until rs.EOF
    msgbox rs.Fields("order_number")
    msgbox rs.Fields("customer_name")
    rs.MoveNext
Loop
rs.Close
dbcon.close
Set rs=nothing
Set dbcon=nothing
==================================================================
   
dialog("Login").Activate
dialog("Login").WinEdit("Agent Name:").Set datatable("agname","Global")
dialog("Login").WinEdit("Password:").Set datatable("pword","Global")
dialog("Login").WinButton("OK").Click
If dialog("Login").Dialog("Flight Reservations").Exist then
dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
dialog("Login").WinButton("Cancel").Click
End If
If window("Flight Reservation").Exist then
    datatable("results","Global")="pass"
    window("Flight Reservation").Close
    else
    datatable("results","Global")="fail"
    end if
=====================================================================
Option explicit
Dim x,y,z
x=datatable.Value("input1",1)
y=datatable.Value("input2",2)
z=cint(x)+cint(y)
datatable.Value("result",1)=z






   

No comments:

Post a Comment