Jump to content

[SOLVED] Array subscripts ? I think this is correct script


Thlitmi
 Share

Recommended Posts

#include <Array.au3>
$q=StringSplit("46,13,54,94,56,78,15,48,26,54,44,84,73,26,64",",")
$p=1
While $p<_ArrayMax($q)
    If $q[$p]=14 Then
    _ArrayDelete($q, $p)
      EndIf
    $p=$p+1
    WEnd
_ArrayDisplay($q)

(5) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded

I think there is no error in it.

And I do not know what is array subscript... Is it array index number ?

Edited by Thlitmi
Link to comment
Share on other sites

#include <Array.au3>
$q=StringSplit("46,13,54,94,56,78,15,48,26,54,44,84,73,26,64",",")
$p=1
While $p<_ArrayMax($q)
    If $q[$p]=14 Then
    _ArrayDelete($q, $p)
      EndIf
    $p=$p+1
    WEnd
_ArrayDisplay($q)

(5) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded

You problem is that _ArrayMax() returns the highest value held in the array, which in your case is 94.

You then try look at the 95th element in the array with $q[$p], which throws an error cause you have exceeded the range of the array.

Replace _ArrayMax() with UBound() and you should be fine.

#include <Array.au3>
$q=StringSplit("46,13,54,94,56,78,15,48,26,54,44,84,73,26,64",",")
$p=1
While $p < UBound($q)
    If $q[$p]=14 Then
    _ArrayDelete($q, $p)
      EndIf
    $p=$p+1
    WEnd
_ArrayDisplay($q)
Edited by Paulie
Link to comment
Share on other sites

Well,I dont fully understand your english, but you are asking what do I want to do with that code ?

_ArrayMax($q) is a number array values, there is 15 values so it will loop 15x times.

is there a better way to tell the loop number of cycles the same as array value number count is ?

Or is there a beter loop than while ? :-D maybe yes, I will try, but you can help me anyway : ) ) ) )

Link to comment
Share on other sites

> Zenda

Now I know that _ArrayMax is a nonsence to use in this script. It was a mistake, that I used it, because I overlooked its description.

""array index is counted from 0 to Ubound() - 1

not from 1 to UBound()""

I know, but it has no meaning in here, because I get the correct number of loops and $p is correct number as needed. And I do not need to work with $p[0]

exept I could use . . .

While $p < $p[0]

(Why didn't I use it in the first place..... ? )

But this topic is [sOLVED]

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