Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help - how can I determine if a column exists?
#1
Solved: 10 Years, 9 Months ago Sad 
Hi!

I have a kind of showstopper problem and desperately need help. I am writing on something like a little testframework that makes the datadrive easier.

In order to do that I import datasheets into tests, but then need to add parameters (=columns) with specified names to the sheet.

The problem is, if I just used....

...sheet.addParameter("bla")...

if a column "bla" already exists, QTP will create another column "bla1". I DONT WANT THAT!

Therfore the simple basic common sense logic is to use ..
..sheet.getParameter("bla")..
...and check if it returns 'nothing', but unfortunately this method throws an error if the column does not exist instead of returning null or whatever.
(I am sorry, but whoever wrote this method must be a nutter).

Surely there is work arounds like trying to use "on error resume next" or using my own hashtable, but there must be a proper way!

So, please, does anyone here know how to check if a column in a sheet exists? Maybe its really simple and I just did not get it..PLEASE!!!

Thanks in advance!!!!
CC
Reply
#2
Solved: 10 Years, 9 Months ago
Hi CC,
I've also the same problem with datatable here is code
datatable.addsheet("my").AddParameter("city","NY") and when i use Datatable.SetNextRow to enter next row value ,it won't go to next row always give null value.So far i'm using GetcurrentRow method and setcurrentrow method .

Thanks,
Reply
#3
Solved: 10 Years, 9 Months ago
yes CC it is indeed simple... try this and you would be able to do it by yourself.

1) Get the count of all columns using .GetParameterCount

2) Loop through all the columns till you get the column you need. ok i would give a hint....
Use this (datatable.value ( i,SheetName))=ColName where:
  • i is the index for for-loop
  • SheetName is the name of sheet, where you want to find the required column and
  • ColName is the name of required column

Let us know how it goes
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#4
Solved: 10 Years, 9 Months ago
Thanks Ankur and Hi new qtp!

Ankur, good solution, Thanks! Why I did not think of that? - I dont know. Me being upset comes in my own way it seems. I was hoping that there was a "proper" solution that does not have a workaround smell..

Cheers!

ps.: Btw, this is the solution I implemented yesterday, but potentially I will switch to your solution because I dont like on error resume.

Code:
set col=nothing
On error resume next
set col=sheet.getParameter(columnName)
On error goto 0
if(col is nothing) then    'column did not exist
        sheet.addParameter columnName, valueToPut
else   'column did exist
        DataTable.Value(columnName, sheetName)=valueToPut
end if
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  to count the number of used rows in a particular column sujaravi123 3 10,917 06-12-2013, 03:17 PM
Last Post: sujaravi123
  How to recognize table row and column siwani 4 4,811 04-05-2012, 05:06 PM
Last Post: verma.vik6
  text exists or not sujaravi123 3 5,039 11-09-2011, 11:57 PM
Last Post: as_srini
  Reading xls by column name anbarasu 2 3,060 04-05-2010, 12:26 PM
Last Post: Saket
  how to check if selection in menu exists.. Anil Kumar 1 3,313 10-15-2009, 08:45 PM
Last Post: jsknight1969

Forum Jump:


Users browsing this thread: 1 Guest(s)