1. logic or function of counting the no of subfolders under the main folder in tree structure.
counter = 0
Function CountFolders(currentFolder)
for each folder in currentFolder.SubFolders
counter = counter + 1
CountFolders(folder)
Next
End Function
CountFolders
(CreateObject("Scripting.FileSystemObject").GetFolder("d:\temp") )
MsgBox(counter)
It counts only first level subfolders :)))
FCount = 0
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFname = oFSO.GetFolder("D:\C:\Documents and
Settings\cc_gubhi\Desktop\Gpubhi_folder") ' Folder Path
Set vFiles = oFname.subfolders
For each vFileItem in vFiles
FCount = FCount + 1
Next
msgbox FCount
Set oFSO = Nothing
Set oFname= Nothing
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TestFolder = FSO.GetFolder("C:\Documents and Settings")
Set SubFolders= TestFolder.SubFolders
MsgBox(SubFolders.Count)
1 What is use of library file and what is contains.?
2 What is difference between writing discripting programming and writing
code in library file.?
All the thing s that you can not do in the QTP can be done in vb script eg.
implementing business logic.. This code can be written in the vb script in
the library file. using library files you can separe the code so u will get
kind of modularity in the code.
2. When the objects in the AUT are dynamic in nature the we can use DP for
identifying the objects DP code can be written in the library file.
DP is a kind of programming which eliminate the existence of the OR.
You can pass the property value pair to identify the object or Use
Description object to do the same..
how can write a discriptive program to check first five check boxes out of ten check boxes.
Dim strChkBox
Dim intCntr
Dim intMaxChkbxCnt
Dim intTotalChkboxes
Set strChkBox=Description.create()
strChkBox("micclass").Value="WebCheckbox"
Set
intMaxChkbxCnt=Browser("YahooMail").Page("YahooInbox").ChildObjects(strChkBox)
intTotalChkboxes=intMaxChkbxCnt.Count()
For intCntr=1 To intTotalChkboxes
If intCntr<=5 Then
Browser("YahooMail").Page("YahooInbox").WebCheckBox(intCntr).Set
"ON"
Else
Exit For
Next
If an object attributes are changing in runtime, it is different. Often we can
handle dynamic changes by using regular expression, but sometimes RE doesn't
help. Here is an example:
Static Object Description:
Set oDesc = Description.Create()
oDesc("html tag").Value = "IMG"
oDesc("image type").Value = "Plain Image"
oDesc("html id").Value = "cal.*BOseries::Calendar::.*::on_sale::0"
oDesc("micclass").Value = "Image"
oDesc("file name").Value = "cal.gif"
Dynamic Object Description:
Set oDesc = Description.Create()
oDesc("html tag").Value = "IMG"
oDesc("image type").Value = "Plain Image"
oDesc("html id").Value = "cal.*BOseries::Calendar::.*::on_sale::0"
oDesc("micclass").Value = "Image"
oDesc("file name").Value = "cal.gif"
* oDesc("index").Value = ActualIndex*
Sort out data in ascending/descending order in data table
DataTable.ExportSheet "D:\Sort.xls" ,"Action1"
RowCnt = DataTable.GetSheet("Action1").GetRowCount
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Application.Visible = True
Set Book = ExcelApp.Workbooks.Open("D:\Sort.xls")
Set Sheet = Book.Worksheets("Action1")
Sheet.Range("A2:A" &(RowCnt+1)).Sort Sheet.Range("A2")
Book.SaveAs "D:\Sorted.xls"
ExcelApp.Application.Quit
DataTable.ImportSheet "D:\Sorted.xls", "Action1", "Action1"
RowCnt = DataTable.GetSheet("Action1").GetRowCount
ReDim Arr(0)
If (UBound(Arr) < RowCnt) Then
ReDim Preserve Arr(RowCnt-1)
End If
For i = 0 to (RowCnt-1)
Arr(i) =
DataTable.GetSheet("Action1").GetParameter("RollNos").ValueByRow(i+1)
Next
For i = 0 to UBound(Arr)
For j = i+1 to UBound(Arr)
If (Arr(i) Arr(j)) Then
Tmp = Arr(j)
Arr(j) = Arr(i)
Arr(i) = Tmp
i = i - 1
Exit For
End If
Next
Next
For i = 0 to (RowCnt-1)
DataTable.GetSheet("Action1").GetParameter("RollNos").ValueByRow(i+1)
= Arr(i)
Next
counter = 0
Function CountFolders(currentFolder)
for each folder in currentFolder.SubFolders
counter = counter + 1
CountFolders(folder)
Next
End Function
CountFolders
(CreateObject("Scripting.FileSystemObject").GetFolder("d:\temp") )
MsgBox(counter)
It counts only first level subfolders :)))
FCount = 0
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFname = oFSO.GetFolder("D:\C:\Documents and
Settings\cc_gubhi\Desktop\Gpubhi_folder") ' Folder Path
Set vFiles = oFname.subfolders
For each vFileItem in vFiles
FCount = FCount + 1
Next
msgbox FCount
Set oFSO = Nothing
Set oFname= Nothing
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TestFolder = FSO.GetFolder("C:\Documents and Settings")
Set SubFolders= TestFolder.SubFolders
MsgBox(SubFolders.Count)
1 What is use of library file and what is contains.?
2 What is difference between writing discripting programming and writing
code in library file.?
All the thing s that you can not do in the QTP can be done in vb script eg.
implementing business logic.. This code can be written in the vb script in
the library file. using library files you can separe the code so u will get
kind of modularity in the code.
2. When the objects in the AUT are dynamic in nature the we can use DP for
identifying the objects DP code can be written in the library file.
DP is a kind of programming which eliminate the existence of the OR.
You can pass the property value pair to identify the object or Use
Description object to do the same..
how can write a discriptive program to check first five check boxes out of ten check boxes.
Dim strChkBox
Dim intCntr
Dim intMaxChkbxCnt
Dim intTotalChkboxes
Set strChkBox=Description.create()
strChkBox("micclass").Value="WebCheckbox"
Set
intMaxChkbxCnt=Browser("YahooMail").Page("YahooInbox").ChildObjects(strChkBox)
intTotalChkboxes=intMaxChkbxCnt.Count()
For intCntr=1 To intTotalChkboxes
If intCntr<=5 Then
Browser("YahooMail").Page("YahooInbox").WebCheckBox(intCntr).Set
"ON"
Else
Exit For
Next
If an object attributes are changing in runtime, it is different. Often we can
handle dynamic changes by using regular expression, but sometimes RE doesn't
help. Here is an example:
Static Object Description:
Set oDesc = Description.Create()
oDesc("html tag").Value = "IMG"
oDesc("image type").Value = "Plain Image"
oDesc("html id").Value = "cal.*BOseries::Calendar::.*::on_sale::0"
oDesc("micclass").Value = "Image"
oDesc("file name").Value = "cal.gif"
Dynamic Object Description:
Set oDesc = Description.Create()
oDesc("html tag").Value = "IMG"
oDesc("image type").Value = "Plain Image"
oDesc("html id").Value = "cal.*BOseries::Calendar::.*::on_sale::0"
oDesc("micclass").Value = "Image"
oDesc("file name").Value = "cal.gif"
* oDesc("index").Value = ActualIndex*
Sort out data in ascending/descending order in data table
DataTable.ExportSheet "D:\Sort.xls" ,"Action1"
RowCnt = DataTable.GetSheet("Action1").GetRowCount
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Application.Visible = True
Set Book = ExcelApp.Workbooks.Open("D:\Sort.xls")
Set Sheet = Book.Worksheets("Action1")
Sheet.Range("A2:A" &(RowCnt+1)).Sort Sheet.Range("A2")
Book.SaveAs "D:\Sorted.xls"
ExcelApp.Application.Quit
DataTable.ImportSheet "D:\Sorted.xls", "Action1", "Action1"
RowCnt = DataTable.GetSheet("Action1").GetRowCount
ReDim Arr(0)
If (UBound(Arr) < RowCnt) Then
ReDim Preserve Arr(RowCnt-1)
End If
For i = 0 to (RowCnt-1)
Arr(i) =
DataTable.GetSheet("Action1").GetParameter("RollNos").ValueByRow(i+1)
Next
For i = 0 to UBound(Arr)
For j = i+1 to UBound(Arr)
If (Arr(i) Arr(j)) Then
Tmp = Arr(j)
Arr(j) = Arr(i)
Arr(i) = Tmp
i = i - 1
Exit For
End If
Next
Next
For i = 0 to (RowCnt-1)
DataTable.GetSheet("Action1").GetParameter("RollNos").ValueByRow(i+1)
= Arr(i)
Next
Post a Comment