Search code examples
vbscriptqtphp-uft

In UFT, what value does an empty Data Cell hold? Is it an empty string or null?


In UFT, you have the possibility to use 'Data' which is essentially an excel sheet which can be used to drive tests.

My question is, if one of these cells is blank, is its value an empty string or is it null? Either way I can get around it but I'm curious so I can help map the rest of the problem out in my head.


Solution

  • First of all, there is no data function I know of. You probably are referring to the DataTable.Value method instead.

    DataTable.Value should always return the empty string for empty cells.

    As to the question about performance -- no, I would not expect a bottleneck here. And even if -- optimizing for a performance problem you don´t yet face is called premature optimization. Don´t do that. Today´s CPUs are too fast for you to sense the difference between IsEmpty, IsNull, or checking for empty string equality. There usually are other operations that consume much more runtime, and are well more worth optimizing.

    The Null value and the IsNull function are seldomly used in VBScript, or, for that matter, QTP/UFT.

    You can think of Empty and IsEmpty existing for variables that have never received a value (or that explicitely received Empty).

    In contrast to that, Nothing is useful for initializing a variable to an Empty-like value if that variable is to hold an object reference later, because Is Nothing returns a valid value for such variable in both cases (case 1: uninitialized, i.e. initialized to Nothing, and case 2: assigned to a valid object instance), while Is Nothing would fail if the variable contains Empty (RTE: "object required"). Similarily, leaving unitialized object reference variables initialized to Empty (think about that, because that´s what happens!) and later assigning that variable to another variable using Set (as you have to because it possibly holds an object reference in the non-empty case) will fail if the contained value is Empty (you´d need to use a normal assignment with = and without Set) while it will succeed (i.e. does not RTE) if it contains Nothing (or an object reference).

    And yes, this all being said, it is quite counterintuitive that DataTable.Value returns an empty string for an empty cell, and not the Empty value.

    Adding to the confusion potential, Empty = "" always returns true, which might not be what one would expect, because hey! an empty string value is by definition a string value, just like a non-empty string, so why should it be considered to be equal to Empty? But it is, because to do the comparison, Empty is converted to a string, and CStr (Empty) is the empty string, which of course is "".