Micro Focus QTP (UFT) Forums
Data Table Query - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Data Table Query (/Thread-Data-Table-Query)



Data Table Query - Suma Parimal - 01-18-2014

How to fetch the particular cell data in Global/Local sheet? How to check whether that cell is editable or not? Please give me the VB script statement for this.


RE: Data Table Query - supputuri - 01-19-2014

Hi there,
we don't have any pure vbscripting methods to get the value from datasheet as it's a QTP specific feature.
Please find the below code which will get the required out out (if i understood your question correctly)
Code:
msgbox GetDataTableCellValue(1,7,2)
Function GetDataTableCellValue(Sheet,Row,Col)
              Dim iRowNumber
              Dim siSheet
              Dim sColumnName
    iRowNumber = Row
    siSheet= Sheet
    sColumnName = GetParameterNumber(siSheet,Col)
    If  iRowNumber <= DataTable.GetSheet(siSheet).GetRowCount Then
        DataTable.GetSheet(siSheet).SetCurrentRow iRowNumber
        GetDataTableCellValue = DataTable.GetSheet(Sheet).GetParameter(sColumnName)    
    Else
        msgbox "The Row '" & iRowNumber & "' does not exit. Please provide a valid row number.",0+16,"Invalid Row Number"
        ExitTest
    End If
End Function
Function GetParameterNumber(Sheet,sParameterNumber)
    On Error Resume Next
    Set oSheet = DataTable.GetSheet(Sheet)
    If oSheet.GetParameterCount = 0 Then
    'If Err.Number <>0  Then
        msgbox "The sheet '" & Sheet & "' does not exit. Please provide a valid sheet name (or) number.",0+16,"Invalid DataSheet Name"
        Set oSheet = Nothing
        ExitTest
    End If
    If  oSheet.GetParameterCount >= sParameterNumber Then
       For iParNumber = 1 to oSheet.GetParameterCount
                GetParameterNumber = oSheet.GetParameter(sParameterNumber).Name
       Next
       Set oSheet = Nothing
    Else
        msgbox "The Column  '" & sParameterNumber & "' does not exit. Please provide a valid column number.",0+16,"Invalid Column Number"
        ExitTest
    End If
End Function

By default all the cells in the runtime datatable are editable. Use the value method of Datatable to edit the value. Note: you can see the new value in the runtime datatable only.

Let me know if you need any more info.


RE: Data Table Query - Suma Parimal - 01-20-2014

Hi Supputuri,

Thank you for your reply with solution. Can you let me know the below statement we can use to get the data in the datatable.

Code :

Code:
Dim Value
Value = datatable(row,column)
print(Value)



RE: Data Table Query - supputuri - 01-20-2014

No, you can not.
But there is a simple way you can do the same.

Code:
Datatable.SetCurrentRow row
Value = datatable(col,sheetnumber)
print Value
But you have to make sure that "Run Only One Iteration" option under File>Test Settings>Run tab. Otherwise, you will get the entire column values.


RE: Data Table Query - Suma Parimal - 01-21-2014

Thank you supputuri, it wil help me a lot.