[thelist] ASP: checking for empty array
Warden, Matt
mwarden at odyssey-design.com
Thu Apr 12 21:48:55 CDT 2001
> Here's my 2 cents, since I gave such a horribly wrong answer:
Nah, it was a good shot. That's actually originally what came to my mind.
> Test Two
>
> <% Dim varTest(0), varTest1(0)
> varTest(0) = "blah"
>
> response.write isEmpty(varTest) & "<br>" & vbCRLF
> response.write isEmpty(varTest1) & "<br>" & vbCRLF
> %>
>
> Returns:
>
> False
> False
Ok, see... this also came to my mind. However, I'm not sure that what you
are creating above with varTest1 is actually an empty array. And this is the
problem. There's NOTHING on msdn.microsoft.com/scripting about what exactly
an empty array is. Personally, I'm inclined to think that it is an array
with no "keys" nor values. So, if you dim an array with a bound of 0, it
ain't empty.
BUT, I don't even think that isEmpty() would work. From what I can find, it
can test on numeric-type variables and string-type variables. An array is
neither.
I once thought that what he wanted was isArray(). Nope. It *IS* an array (or
at least that's what it says), just an empty one. In VB, an empty array
would be written like:
Dim myArray() As String
Looks like VBScript needs this syntax:
myArray = Array()
So, now I can do some testing (now that I can actually create an empty
array!!!):
Interestingly, isNothing() on the empty array returned false, but once I
redimmed it to have "keys" i got a mismatch error.
Other than that, there doesnt' seem to be a function to determin if an array
is empty.
isArray returned true for an empty array, a redimmed array, and an array
with array(0) defined with a value
isEmpty returned false for an empty array, a redimmed array, and an array
with array(0) defined with a value
isNull returned false for an empty array, a redimmed array, and an array
with array(0) defined with a value
So, the only thing that you could possibly use is the error from
isNothing(). Makes me feel dirty, but if there's no other choice (I can't
imagine there's not away to do this.. but google turns up NOTHING useful).
I hope this helps... a little.
--
mattwarden
mattwarden.com
More information about the thelist
mailing list