[thelist] ASP: checking for empty array
Anthony Baratta
Anthony at Baratta.com
Thu Apr 12 21:21:20 CDT 2001
Here's my 2 cents, since I gave such a horribly wrong answer:
Test Two
<% Dim varTest(0), varTest1(0)
varTest(0) = "blah"
response.write UBound(varTest) & "<br>" & vbCRLF
response.write UBound(varTest1) & "<br>" & vbCRLF
%>
Returns:
0
0
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
Test Three
<% Dim varTest(0), varTest1(0)
varTest(0) = "blah"
response.write isEmpty(varTest(0)) & "<br>" & vbCRLF
response.write isEmpty(varTest1(0)) & "<br>" & vbCRLF
%>
Returns:
False
True
This means to me that you'll need to iterate through a loop to test all
parts of the array.
Option One
<% Dim varTest(0), varTest1(0)
varTest(0) = "blah"
varCount = 0
for each fld in varTest
if isEmpty(fld) then
response.write "varTest - " & varCount & ": True<br>"
else
response.write "varTest - " & varCount & ": False<br>"
end if
varCount = varCount + 1
next
varCount = 0
for each fld in varTest1
if isEmpty(fld) then
response.write "varTest1 - " & varCount & ": True<br>"
else
response.write "varTest1 - " & varCount & ": False<br>"
end if
varCount = varCount + 1
next
%>
Returns:
varTest - 0: False
varTest1 - 0: True
Option Two
<% Dim varTest(0), varTest1(0)
varTest(0) = "blah"
for x = 0 to UBound(varTest)
if isEmpty(varTest(x)) then
response.write "varTest - " & x & ": True<br>"
else
response.write "varTest - " & x & ": False<br>"
end if
next
for x = 0 to UBound(varTest1)
if isEmpty(varTest1(x)) then
response.write "varTest1 - " & x & ": True<br>"
else
response.write "varTest1 - " & x & ": False<br>"
end if
next
%>
Returns:
varTest - 0: False
varTest1 - 0: True
---
Anthony Baratta
President
Keyboard Jockeys
More information about the thelist
mailing list