Jump to content
Sign in to follow this  
LurchMan

Array / Loop Question

Recommended Posts

LurchMan

Hey Everyone -

In one part of this script I'm writing it finds string matches in an array, then goes through and deletes them according to the index array.

I have one section setup so that if the index array is empty (meaning no matches found) then it exits the loop.

I'm checking to see if the first element is empty like this:

If $aIndex[0] = "" Then ExitLoop

The problem is that if $aIndex[0] = 0 then it exits the loop, is this the expected result by using that? I have also tried checking to see if it is not an array without any luck.

Please let me know if you would like more explination.

Thanks for any help in advance!

Lurch


Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites
memoryoverflow

Hard to tell what you're trying with this small piece, but...

Why don't you simply test If Not $aIndex[0] ?

O well - now I see what you're trying:

perhaps If 'x' & $aIndex[0] = 'x' ... ?

Edited by memoryoverflow

(The signature is placed on the back of this page to not disturb the flow of the thread.)

Share this post


Link to post
Share on other sites
LurchMan

O well - now I see what you're trying:

perhaps If 'x' & $aIndex[0] = 'x' ... ?

Can you explain on that a little further?

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites
memoryoverflow

Like your approach, it may not work for you, anyway, if you want to test for the existence of $aIndex[0].

In that case, you'd have to test UBound($aIndex).

But all that's rather guessing as long as you don't post a bigger snippet, showing clearer what you want to do.

If you're sure that the element exists, then concatenating it with a string makes sure it's interpretated as a string (and not as number 0) a 0 in the variable would lead to test 'x' vs 'x0', which is ovbiously false, otherwise you compare the number 0 (wich is false) vs string "" (which is also false) and get If false=false, which is true - there's a typo in my example, brackets missing.

Edited by memoryoverflow

(The signature is placed on the back of this page to not disturb the flow of the thread.)

Share this post


Link to post
Share on other sites
LurchMan

You''re awesome man, I never thought of doing it that way but it works perfect everytime now.


Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×