Jump to content

Recommended Posts

Posted

Ok...so I'm trying to search through the Array that StringSplit created and delete the elements that have more than 3 characters. However, when I implement this code I keep getting an "Array variable has incorrect number of subscripts...." error message. What am I doing wrong??

$aHTMLfinal = StringSplit($sHTMLfinal, " ")
  
  $i_Base = 0
  $I_Ubound = UBound($aHTMLfinal) - 1
 

  For $i = $i_Base To $i_UBound
    

    $sitem = $aHTMLfinal[$i]
        
       
      if Stringlen($sitem) > 3 then
    
        _Arraydelete($aHTMLfinal,$i)
    

        endif
        
        
  Next

Thanks!

Posted

Ok...so I'm trying to search through the Array that StringSplit created and delete the elements that have more than 3 characters. However, when I implement this code I keep getting an "Array variable has incorrect number of subscripts...." error message. What am I doing wrong??

$aHTMLfinal = StringSplit($sHTMLfinal, " ")
  
  $i_Base = 0
  $I_Ubound = UBound($aHTMLfinal) - 1
 

  For $i = $i_Base To $i_UBound
    

    $sitem = $aHTMLfinal[$i]
        
       
      if Stringlen($sitem) > 3 then
    
        _Arraydelete($aHTMLfinal,$i)
    

        endif
        
        
  Next

Thanks!

The problem lies in ArrayDelete - every time you do ArrayDelete it returns adjusted array which is smaller than original array and eventually your count goes beyond the size of array.

You can run through array starting from last element instead of first element or you can use another array to store values temporarily.

Posted

The problem lies in ArrayDelete - every time you do ArrayDelete it returns adjusted array which is smaller than original array and eventually your count goes beyond the size of array.

You can run through array starting from last element instead of first element or you can use another array to store values temporarily.

Ok...so I changed it to run from the last to the first. Except it's not removing the ones that have greater length than 3. I even put in a test label to check and it's not getting the lengths at all. Anyone know why?

$aHTMLfinal = StringSplit($sHTMLfinal, " ")
  
  $i_Base = 1
  $I_Ubound = UBound($aHTMLfinal) - 1
 

  For $i = $i_UBound To $i_Base
    
        

    $sitem = $aHTMLfinal[$i]
           
        Guictrlsetdata($testlabel, Stringlen($sitem))

      if StringLen($sitem) > 3 then
    
        $aHTMLfinal= _Arraydelete($aHTMLfinal,$i)
        


        endif
        
        
  Next
  • Moderators
Posted

You could try this to see if it works:

$aHTMLfinal = StringSplit($sHTMLfinal, " ")
Local $aStoreDelete = '', $i_Base = 0, $I_Ubound = UBound($aHTMLfinal) - 1
For $i = $i_Base To $i_UBound
    If StringLen($aHTMLfinal[$i]) > 3 Then
        $aStoreDelete &= $i & Chr(01)
    EndIf
Next
$aStoreDelete = StringSplit(StringTrimRight($aStoreDelete, 1), Chr(01))
For $x = 1 To UBound($aStoreDelete) - 1
    _ArrayDelete($aHTMLfinal, $aStoreDelete[$x])
Next
Untested, but it should let you check for all lengths greater than 3, and store them for deletion after the first loop.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

I tried your code Smoke but it didn't do anything. It actually brought up an error on this line

$aStoreDelete &= $i & Chr(01)

so I tried is8591's suggestion and it actually runs through the loop this time (proven by my little test label) but now it's giving me a "subscript used with non-array variable" error on this line

$sitem = $aHTMLfinal[$i]

Which doesn't make sense because 1) I've proven it goes through the loop once because my label placing and 2) it's defined as an array already

So what can I do now?

  • Moderators
Posted (edited)

You need Beta or fix the lines.... to fix them

$aStoreDelete = $aStoreDelete & $i & Chr(01)

Is the same as

$aStoreDelete &= $i & Chr(01)

Edit:

Provided like example.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

I tried your code Smoke but it didn't do anything. It actually brought up an error on this line

$aStoreDelete &= $i & Chr(01)

so I tried is8591's suggestion and it actually runs through the loop this time (proven by my little test label) but now it's giving me a "subscript used with non-array variable" error on this line

$sitem = $aHTMLfinal[$i]

Which doesn't make sense because 1) I've proven it goes through the loop once because my label placing and 2) it's defined as an array already

So what can I do now?

You should always refer to help file to see details for any functions.

Straight from Help:

Remarks

If the array passed in has only 1 element, this function returns an empty string.

I guess the last time you call ArrayDelete you only have 1 element and it returns a string not array.

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
  • Recently Browsing   0 members

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