Interview question

29 views
Skip to first unread message

vijay kanaparthi

unread,
Apr 21, 2012, 10:10:46 AM4/21/12
to QTP - HP Quick Test Professional - Automated Software Testing
Hi Frnz..

Q-I have an excel file which have the columns like Emp_Name,Emp_id,
Emp_Salary.

how i will get all the details of the employee who is having salary
5000.Through QTP only..


sujit kumar

unread,
Apr 21, 2012, 2:51:02 PM4/21/12
to mercu...@googlegroups.com
Hi,

''assuming ur Column like this
''EmpName | EmpID | Salary"

Call Fn_PrintEmpDetials("5000")


Function Fn_PrintEmpDetials(empSal)
Dim objExcel,objWorkBook 
Dim objvalueFind,sAddress,aRowCol,usedRowCount
Set objExcel = CreateObject("Excel.Application")
objExcel.visible=False
objExcel.AlertBeforeOverwriting=False
objExcel.DisplayAlerts=False
Set objWorkBook = objExcel.Workbooks.Open ("c:\ExcelFile.xls") 
Set Cells=objSheet.Cells
Set objvalueFind=objSheet.UsedRange.Find("EmpName") 
If Not objvalueFind is Nothing  Then
sAddress=objvalueFind.Address
aRowCol=Split(sAddress,"$",-1,1)
'now u have column name EmpName
empNameColumn=aRowCol(2)
empNameRow=aRowCol(1)
End If
Set objvalueFind=objSheet.UsedRange.Find("Salary") 
If Not objvalueFind is Nothing  Then
sAddress=objvalueFind.Address
aRowCol=Split(sAddress,"$",-1,1)
'now u have column name of salary 
salaryColumn=aRowCol(2)
salaryRow=aRowCol(1)
For iRowIteration=1 to objSheet.UsedRange.Rows.Count
getSalary=Cells(aRowCol(2),aRowCol(1)).Value
If Cstr(getSalary)=Cstr(empSal)Then
'it will print name of employe which having 5000 salary
print Cells(empNameColumn,aRowCol(1)).Value
'it will print salary of employe which having 5000 salary
print Cells(salaryColumn,aRowCol(1)).Value
End If
Next
End If
objExcel.ActiveWorkbook.Save 
objExcel.Workbooks(1).Close
objExcel.Quit 
Set objSheet=Nothing
Set objExcel=Nothing
End Function
-- 
Note: few Variable declaration are missing please check It will work fine
let me know u have further any query

:)
Thanks & Regards
Sujit



--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to Mercu...@googlegroups.com
To unsubscribe from this group, send email to
MercuryQTP+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en




Deepak Kumar Mahapatro

unread,
Apr 22, 2012, 3:33:47 AM4/22/12
to mercu...@googlegroups.com
you can use ADODB objects to access the excel and execute sql query
--
Regards,
Deepak

Anish Pillai

unread,
Apr 22, 2012, 11:26:08 AM4/22/12
to mercu...@googlegroups.com
Hi Vijay,

There are 2 ways you can read data from excel sheet into QTP.

1) Use the native functions exposed by excel to directly copy the the data from excel. This is technically the functionality exposed by MS Excel. So in one way this has nothing to do with QTP. You can do this without QTP also. The code that Sujit mentioned above uses this method to retrieve values from the xls.

2) The second method is the QTP specific code where you first import the excel data into QTP datatable. After the data is imported, you use the data table functions to copy the code.


One more query. In interviews, do they ask to write the code? Or they just ask the logic or algo? Because I'm not really sure whether people will remember the syntax and all.




--
Regards,
Anish Pillai
My QTP Blog

Reply all
Reply to author
Forward
0 new messages