Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Null?

Status
Not open for further replies.

rmc

Programmer
Feb 1, 2001
11
0
0
GB
I'm trying to find a short means of determining if an array contains no values (its storing the input from a multiple select box on a web page and my script works fine until nothing is selected in the list and the form submitted)

I think I need to use Null but can't figure out how? Any help much appreciated
 
You can ask if array(element) = null

This one always gets me, too -- if the above doesn't work, then try asking if it's

= empty

--or--

= ""

Ya know, though... probably the most reliable way is to initialize all the elements to some sentinel value, and then you know what you are looking for. For example, if you had a 10 element array that you would be stuffing with numbers, then I would probably just initialize them all to either 0 or 99 or something that I knew wouldn't normally be put into the array:

for i = 1 to 10
array(i) = 0
next

Then go about your business, and just check for 0 -- then you know for sure, and it will always work.

good luck! :)
Paul Prewett
 
Actually you can't use = null.

You need to use the function isNull

function ArrayContainsNull(ary) 'Returns boolean
for i = lbound(ary) to ubound(ary)
if isNull(ary(i)) then
'Short circuit if value is null
ArrayContainsNull = true
exit function
end if
next
ArrayContrainsNull = false
end function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top