Micro Focus QTP (UFT) Forums
Please help - how can I determine if a column exists? - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Please help - how can I determine if a column exists? (/Thread-Please-help-how-can-I-determine-if-a-column-exists)



Please help - how can I determine if a column exists? - ConstantChange - 02-28-2008

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


RE: Please help - how can I determine if a column exists? - newqtp - 02-28-2008

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,


RE: Please help - how can I determine if a column exists? - Ankur - 02-28-2008

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


RE: Please help - how can I determine if a column exists? - ConstantChange - 02-29-2008

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