Jump to content

Stripping Blank Elements ...


Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...