Jump to content
Sign in to follow this  
jaberwacky

Stripping Blank Elements ...

Recommended Posts

jaberwacky

Hi, me again...

If I had an array like this: http://content.imagesocket.com/images/ArrayDisplay388.jpg

Could I make another array that would only include the numbers?

Did I explain thoroughly?

Matt

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites
youknowwho4eva

Yes you can make it all numbers. Look up _arraydelete and _isnumber in the help file. That should get you on the right track.


Giggity

Share this post


Link to post
Share on other sites
jaberwacky

Yes you can make it all numbers. Look up _arraydelete and _isnumber in the help file. That should get you on the right track.

Hey, sounds good. I'll give a try and report back.

Share this post


Link to post
Share on other sites
jaberwacky

Hey, sounds good. I'll give a try and report back.

Ok, as soon as I added _ArrayDelete() into my code it throws this error message: "Array variable has incorrect number of subscripts or subscript dimension range exceeded." I ran the array through isArray() which reports that it is an array!

If isArray( $initialArray ) Then msgBox( 0 , "" , "array" )

For $i = 0 to 31 Step 1
     If $initialArray[ $i ] = 99 Then
          _arrayDelete( $initialArray , $i )
     EndIf
Next

Share this post


Link to post
Share on other sites
Jos

When you perform the _ArrayDelete(), the array will have one "record" less, but you are not adapting $i.

To avoid this problem you need to process your array in the reverse direction:

If isArray( $initialArray ) Then msgBox( 0 , "" , "array" )

For $i = 31 to 0 Step -1
     If $initialArray[ $i ] = 99 Then
          _arrayDelete( $initialArray , $i )
     EndIf
Next

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
youknowwho4eva

Hmmm Jos I never thought of doing it that way. Also wouldn't it make it quicker if you added a $i -= 1 so that it doesn't read the same item twice?

Edit: I always put a $i -= 1 in there so it doesn't skip an item and have if @error then exitloop

Edited by youknowwho4eva

Giggity

Share this post


Link to post
Share on other sites
jaberwacky

It just now occurred to me!

This is the idea I had to deal with the problem:

For $i = 0 to UBound( $initialArray ) - 1 Step 1
     If $initialArray[ $i ] = 0 Then _ArrayDelete( $initialArray , $i )
Next

I'm going to try it now...

Share this post


Link to post
Share on other sites
Jos

Hmmm Jos I never thought of doing it that way. Also wouldn't it make it quicker if you added a $i -= 1 so that it doesn't read the same item twice?

Edit: I always put a $i -= 1 in there so it doesn't skip an item and have if @error then exitloop

"there are many roads leading to Rome" :) but in general you would use:

For $i = 0 to Ubound($initialArray)-1

or

For $i = 0 to Ubound($initialArray[0])

Using this would always trigger the error as the For values are only initially set. That is why I normally go for the reverse approach.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
youknowwho4eva

I thought the saying was all roads lead to Rome? I prefer "There's more then one way to skin a cat"


Giggity

Share this post


Link to post
Share on other sites
jaberwacky

I tried the UBound() method.

Then I tried:

For $i = 31 to 0 Step 1
     If $initialArray[ $i ] = 0 Then
          _ArrayDelete( $initialArray , $i )
     EndIf
Next

That stopped the error message but doesn't delete the elements from the array!

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites
youknowwho4eva

You stepping the wrong way. 31 + 1 continued will never = 0.


Giggity

Share this post


Link to post
Share on other sites
jaberwacky

You stepping the wrong way. 31 + 1 continued will never = 0.

Giggity Giggity! I just now realized it and that fixed the prob!!! Thanks to all posters for taking the time! =D

Share this post


Link to post
Share on other sites
Jos

I thought the saying was all roads lead to Rome? I prefer "There's more then one way to skin a cat"

This particular saying has 2 versions:

1. Alle wegen leiden naar Rome

2. Vele wegen leiden naar Rome

Translated 1. is your version and 2. is mine. :)

.. and we never skin cats overhere.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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  

×