However, here is the CoPilot critique of Philipp's simple function from post #7
I suggest you ask it to provide failing test cases for all the problems the A-non-I hallucinated.
- It uses IsNumeric, which accepts values that can be coerced to Double, allowing out-of-range values.
IsNumeric is used, but only to weed out anything that is not any kind of number at all. The limits of IsNumeric are basically correct, but completely irrelevant in the context of the function.
- It uses CDec for range checks, but Decimal conversions can accept values outside the 64-bit integer range due to floating-point parsing and scientific notation.
What? The function does
not use CDec directly for range checks, but explicitly checks for the boundaries of Int64. This problem is a complete hallucination.
- The formatting comparison to detect integer-ness fails on scientific notation, leading zeros, and trailing decimal points.
- The function indeed won't accept a string containing a number in scientific notation. - But should it? Probably yes, but it is up for debate.
- That statement is incorrect for leading zeroes.
- The function indeed won't accept a string with trailing decimal point or a zero decimal fraction. Another topic for debate. Based on VBA default behavior: The supplied number can be converted without loss to an Int64, but it currently is not because it indicates a decimal type.
- It mishandles the minimum 64-bit integer boundary value because of how it calculates the format string length.
What? Checking Int64 boundaries and the format string length are not related in any way within that function.
- It can incorrectly accept out-of-range values that appear valid after Decimal rounding.
Nope. Relevant decimal rounding may only happen for values far outside the valid range of an Int64.
Overall, this function is unsafe and inaccurate for validating 64-bit integers.
Overall, Copilot is unsafe and inaccurate for reviewing VBA code. ;-)
Well, but seriously, what to make of this "critique"?
It caught the problem with scientific notation. Even if one decides to reject scientific notation, it should have been a thought-through deliberate decision, but I admit I completely missed it.
To a lesser extent, the same applies to numbers with trailing decimal points and zero-fractions.
So, the bottom line is: One bullet point pointing out valid issues against four hallucinated non-issue points.
I personally would perceive the pointed out problem valuable enough to tolerate the accompanying garbage.
But what with less experienced programmers? They might have their valid and usable work shot down by an AI which, as usual, phrases its reply with an abundance of confidence while in fact being utterly wrong with 80% of its reply.
I find it highly questionable to post such an "AI review" here in the forum without any personal classification or review added. - Not because I feel personally offended or slandered but because it can have profound negative effects on people just starting to learn programming VBA.