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......
Print | posted on Tuesday, June 17, 2008 11:06 AM