homepage Welcome to WebmasterWorld Guest from 54.221.175.46
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
Arrays - Clearing and Testing
Arrays - Clearing and Testing
buck1107




msg:4223963
 4:49 pm on Oct 29, 2010 (gmt 0)

Hi,
I'm currently working with an Classic ASP page (VB Script) that utilizes the same array at several points during the page. After each use, I erase the array. The problem is, what is the best way to detect if the array is empty through an if/then statement?

Here's how I've been erasing the arrays:
If IsArray(a) Then
Erase a
End If


In the outer If/Then statement, I test for
IsArray(array)
The array that had been erased still exists.

On the inner If/Then statment, I'd been using
Not IsEmpty(array)
as well as
UBound(array)<>-1
although I would get an error message when using the latter (out of range), while in the former, an erased array would show as "true" (not empty). In the meantime, I've created flags as a workaround, but it's not the ideal situation. Any help or resources would be greatly appreciated.

Thanks!

 

Demaestro




msg:4224013
 7:15 pm on Oct 29, 2010 (gmt 0)

not sure of the syntax but I can offer you a logic change.

Instead of erasing the array you should set it to an empty array, then instead of checking if it exists.... check to see if it's length is > zero

buck1107




msg:4224048
 8:31 pm on Oct 29, 2010 (gmt 0)

Thanks,
From what I've read, it seems that the Erase method clears the array. Would the ReDim method be preferrable in this case?

Also, in determining if the array is greater than 0, I can't use UBound. Do the following look correct? I'm not familiar with "Is Nothing". When I added it, I got the "object required" message.

If Not(IsNull(vArray(a))) And Not(IsEmpty(vArray(a))) And Not(a) Is Nothing)


Thanks again!

Demaestro




msg:4224064
 9:08 pm on Oct 29, 2010 (gmt 0)

buck,

My asp is about 9 years rusty so I am not in a position to advise on what would be preferable.

I did a little looking and it appears that erase is a correct method, I don't know if it is the best way to go about it.

Curious why you can't use Ubound?

buck1107




msg:4224067
 9:16 pm on Oct 29, 2010 (gmt 0)

Thanks
When I use this:
If (UBound(arrCompareItem1_js)<>-1) Then

It results in:
"Subscript out of range: UBound"

Demaestro




msg:4224101
 10:47 pm on Oct 29, 2010 (gmt 0)

try

If (UBound(a) > 0) Then

buck1107




msg:4224959
 4:42 pm on Nov 1, 2010 (gmt 0)

Thanks!

I found that
ReDim a(-1) did the trick

That clears the array by setting its upper bound to -1.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved