Jennifer
03-10-2013, 03:20 PM
I am writing two little Excel macros.
IsAType checks for valid data in a list of cells. It is passed a data type ("Date", "Num") and a list of cell references. It checks each cell to see if it contains valid data of the specified type. If they all do, it returns "TRUE". Otherwise, it returns "FALSE".
IsNotEmpty checks for empty cells. It is passed a list of cell references. It checks each cell to see if it is empty. If all cells are empty, it returns "TRUE". Otherwise, it returns false.My question is what should I do if it gets passed a null list? Does it make more sense to return TRUE (even though no cells passed the test) or FALSE (even though none failed it).
In my case, I will probably check for the null case and return an error. But I was wondering if there is some general programming principle about what to do with null cases.
Would the null case be True because no cells failed the test? That's how the macro is coded. I start out with a TRUE result and return FALSE as soon as I find a cell that fails the test? If so, then the null case would return TRUE
Or would the null case be false because no cells passed the test (even though none failed, either).
I am leaning toward the first one if I don't make it an error.
IsAType checks for valid data in a list of cells. It is passed a data type ("Date", "Num") and a list of cell references. It checks each cell to see if it contains valid data of the specified type. If they all do, it returns "TRUE". Otherwise, it returns "FALSE".
IsNotEmpty checks for empty cells. It is passed a list of cell references. It checks each cell to see if it is empty. If all cells are empty, it returns "TRUE". Otherwise, it returns false.My question is what should I do if it gets passed a null list? Does it make more sense to return TRUE (even though no cells passed the test) or FALSE (even though none failed it).
In my case, I will probably check for the null case and return an error. But I was wondering if there is some general programming principle about what to do with null cases.
Would the null case be True because no cells failed the test? That's how the macro is coded. I start out with a TRUE result and return FALSE as soon as I find a cell that fails the test? If so, then the null case would return TRUE
Or would the null case be false because no cells passed the test (even though none failed, either).
I am leaning toward the first one if I don't make it an error.