QTP: Frailty, thy name is DataTable

I am not a big fan of the datatable in QTP.

This statement comes as no surprise to those who know me, and my work. I've always been forced to use it. I do agree that it does allow for ease of using Excel sheets as a data mechanism between me and my manual user; I create an Excel sheet and it becomes the data contract between me and the user.

However, the datatable does me wrong at the worst of times, and in the worst of ways, it seems.

I've threatened to write a replacement for the datatable about a million times, but I've just never taken the time. I need to do that, I think.

Anyway, here's today's gotcha: make sure you are aware of the data types of the cells in your Excel sheet, because QTP is. If you have a cell that you have left as a number, for example, you cannot change the value in the datatable post import dynamically without casting it first.

For example, assume I have a cell in my global sheet named "myNumber" and the format of the cell in Excel is number.

This will not work:
DataTable.Value("myNumber", dtGlobalSheet) = "123"
but, this will:
DataTable.Value("myNumber", dtGlobalSheet) = Clng("123")

Now, I know what you're thinking: I should be compensating for that sort of thing and managing the conversion. Fair statement. But, there's another issue to bear in mind: The first statement above (the one that doesn't work) doesn't generate an error; it just leaves the field as it was. I mean, no error??? That makes finding these little conversion issues painful as heck.

So, from now on, I will only use "text" formatted cells in Excel to avoid this issue.....until I write that replacement......
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Print | posted on Tuesday, June 17, 2008 11:06 AM

Feedback

# re: QTP: Frailty, thy name is DataTable

left by MES at 6/18/2008 2:54 PM Gravatar
<laughs> I too have encountered this issue..but in a different way. I have a set of resuable modules built to generate data where I work too. And verify the data is populated in the forms properly before submitting the form to the system.

Problem is that some business owner somewhere decided it would be "cute" for us to autoformat numbers so that more than 3 digit numbers have a comma separator, ie XX,XXX

The gotcha there...is if you leave it as a text field in the Excel sheet as a "number" you get XXXXX which doesn't match what is displayed as XX,XXX...so what I did was convert all the numbers in the Excel sheet from "text" to "numbers" with no decimal display & a comma separator...and PRESTO now when I pull the value in from the DataTable and compare it to what the site has XX,XXX = XX,XXX

SUCKS but what can you do...
Comments have been closed on this topic.