How To Pass User Input Values to Datatable in QTP

October 08, 2010

In this post , I would like to show how to take user input dynamically and save it to Excel sheet. In very rare cases, We see such thing.Most of cases where we need some manual intervention We will go with this approach.

The syntax to get data from user is ..
Please refer here for more on inputbox

Please refer here for all datatable methods
Please refer here Datatable Assignment.
'Will add a sheet during runtime
'Create a variable how many sheets are present during run time
DataTable.GetSheet(user_input).AddParameter "Emp_No", ""
'Adding parameter as employee Number
DataTable.GetSheet(user_input).AddParameter "Emp_Name", ""
'Adding parameter as employee Name
DataTable.GetSheet(user_input).AddParameter "Emp_sal", ""
'Adding parameter as employee salary
For i = 1 to 3
' Setting the currentrow
    DataTable.Value(1,user_input) = inputbox("Please provide Employee Nummber")
'getting Employee number as input and storing that in the first column
    DataTable.Value(2,user_input) = inputbox("Please provide Employee Name")

    DataTable.Value(3,user_input) = inputbox("Please provide Employee Salary")

You are done. Optionally You can export the sheet to local using exportsheet method.

You Might Also Like