Jump to content
Sign in to follow this  
litlmike

_ArrayDelete Causes "Array variable has incorrect number of subscripts or subscript dimension range exceeded"

Recommended Posts

I am trying to get rid of any Elements in an array that contain only white spaces. But, while looping through with _ArrayDelete it causes the original Ubound to go past the number of elements. I do not have much experience using ReDim or other methods like it. I assume that there must be a way to work around this. Thanks for any help.

$Multi_Cat = GUICtrlRead ($Edit2)
                $aMulti_Cat = StringSplit($Multi_Cat, @CR)
                $LastElement = UBound ($aMulti_Cat)-1

                For $iCC = 0 To $LastElement
                    If StringIsSpace ( $aMulti_Cat[$iCC] ) Then
                        _ArrayDelete ($aMulti_Cat, $iCC)
                    EndIf
                Next

Share this post


Link to post
Share on other sites

Maybe...

$Multi_Cat = GUICtrlRead($Edit2)
$aMulti_Cat = StringSplit($Multi_Cat, @CR)
$LastElement = UBound($aMulti_Cat) - 1
Dim $New_Array

For $iCC = 0 To $LastElement
    If StringIsSpace($aMulti_Cat[$iCC]) Then ContinueLoop
    _ArrayAdd($New_Array, $aMulti_Cat[$iCC])
Next

_ArrayDisplay($New_Array) ; change name..blah..blah

There are alot of great functions inside array.au3.... take a look inside!

8)

Share this post


Link to post
Share on other sites

Hello,

the problem is, that if you delete one element, the number of $LastElement

will be wrong, as there is one element less in the array.

The solution is to turn the for loop around, and work from $LastElement to 0.

ciao

Xandl

Share this post


Link to post
Share on other sites

Take a look at this one I use myself. This might point you to the right direction;

; Removing dashes and white spaces
$pnumber = StringSplit(StringReplace(_ArrayToString($pnumber, ","), "-", ""), ",") ; Removing dashes from Part Numbers
_ArrayDelete($pnumber, 0)

Hope that helps.

Share this post


Link to post
Share on other sites

Thanks for everyone's feedback. I tried all of the approaches until one finally worked. I still can't figure why Valuater's didn't work, but below is what I ended up with. The only scenario I cannot get it to work in, is if the starting elements are WhiteSpace. So it works if the Elements are like this: ['a','b','c'] or ['a','b',' '] or ['a',' ','c ']; but not if it is [' ','b',' c']. Any ideas?

$LastElement = UBound ($aMulti_Cat)-1
                For $iCC = $LastElement To 0 Step -1
                    If StringIsSpace ($aMulti_Cat[$iCC] ) Then
                    _ArrayDelete ($aMulti_Cat, $iCC)
                    EndIf
                Next

Share this post


Link to post
Share on other sites

A special UDF for you :)

Func _CleanStringSpec(ByRef $splitstring, $dataname)
    $splitdata = StringSplit(StringReplace(StringReplace(_ArrayToString($splitstring, "*"), @CRLF, "*"), "-", ""), "*")
    ;_ArrayDelete($splitdata, 0)
    For $x1 = Ubound($splitdata) - 1 To 0 Step -1
        If StringStripWS($splitdata[$x1], 8) = "" Then _ArrayDelete($splitdata, $x1)
    Next
    _ArrayDisplay($splitdata, "CleanStringSpec() Result - " & $dataname)
EndFuncoÝ÷ ØLZ^jëh×6#Include <Array.au3>

Dim $pnumber1[3] = ['a','b','c']
Dim $pnumber2[3] = ['a',' ','c']
Dim $pnumber3[3] = ['a','b',' ']
Dim $pnumber4[3] = [' ','b','c']

_CleanStringSpec($pnumber4, "P4")

Func _CleanStringSpec(ByRef $splitstring, $dataname)
    $splitdata = StringSplit(StringReplace(StringReplace(_ArrayToString($splitstring, "*"), @CRLF, "*"), "-", ""), "*")
    ;_ArrayDelete($splitdata, 0)
    For $x1 = Ubound($splitdata) - 1 To 0 Step -1
        If StringStripWS($splitdata[$x1], 8) = "" Then _ArrayDelete($splitdata, $x1)
    Next
    _ArrayDisplay($splitdata, "CleanStringSpec() Result - " & $dataname)
EndFunc

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  

×
×
  • Create New...