Micro Focus QTP (UFT) Forums
datatable column exist - 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: datatable column exist (/Thread-datatable-column-exist)



datatable column exist - diya - 12-10-2012

hello,

i tried first to import the sheet but could not proceed..the code is,i always get failed
i have an excel with username and password and trying to check to add new column if exists add value if not add column and value...please help

Code:
'datatable.ImportSheet "C:\Documents and Settings\Administrator\Desktop\excelblank.xls",1,"Action1"
'paramcount=datatable.GetSheet("Action1").GetParameterCount
'msgbox paramcount
'For i=1 to paramcount
'    If (datatable.Value(i,"Action1")="Password") then
'        msgbox "passed"
'        else
'        msgbox "failed"
'end if
'
'Next



RE: datatable column exist - elango87 - 12-10-2012

Use the code below,

Code:
Dim paramcount, FindParameter

datatable.ImportSheet "C:\Documents and Settings\Administrator\Desktop\excelblank.xls",1,"Action1"
paramcount=datatable.GetSheet("Action1").GetParameterCount
msgbox paramcount
For i=1 to paramcount
    If  datatable.GetSheet("Action1").GetParameter(i).Name = "Password" Then
        datatable.Value(i,"Action1")="mypassword"
        FindParameter = "Pass"
    End If
Next
If FindParameter <> "Pass" Then
    datatable.GetSheet("Action1").AddParameter "Password","mypassword"
End If

Hope it helps.

Let me know in case if you need any help.

I will post the code for doing it in excel tomorrow.

Thanks,
Elango


RE: datatable column exist - diya - 12-10-2012

got thru on error resume next



Code:
datatable.ImportSheet "C:\Documents and Settings\Administrator\Desktop\excelblank.xls",1,"Action1"
paramcount=datatable.GetSheet("Action1").GetParameterCount
msgbox paramcount


on error resume next
val=DataTable("Result","Action1")
If err.number<> 0 then

MsgBox "Parameter does not exist"
datatable.GetSheet("Action1").AddParameter "results","Added"
Else
Msgbox "Parameter exists"
End If


but for loop not able to proceed further....please help



Thanks Elango....got it



elango can you see the link below and please explain as what he is trying to do...

i also have a question regarding local sheet data and run time data and how to compare

https://www.learnqtp.com/forums/Thread-How-to-rerieve-data-from-xls-compare-with-data-in-data-table



Elango,

Can you please go thru the link below and please tell me the difference and how we compare

https://www.learnqtp.com/forums/Thread-How-to-rerieve-data-from-xls-compare-with-data-in-data-table

i imported and the data is in run time data...what is local data


RE: datatable column exist - elango87 - 12-11-2012

In the post you have specified, he is retrieving a value from the application under test and updating it in the data table. He wanted to compare the value retrieved from the application with the data in the external excel sheet.

I presume that you know the difference between design time data table and run time data table in QTP. If not, google it.

What are you trying to do?

Thanks,
Elango