Sign in to follow this  
Followers 0
e2e4au

Error - Why is this happening

5 posts in this topic

This is the code and error - I am reading in sections from INI file.

The Code

---------------------------------------

$i=UBound($avCRanking)

Do

If _ArrayMax($avCRanking,1) = $avCRanking[$i] Then

$1=StringFormat("%s%s%s%s",$i,"(",_ArrayMax($avCRanking,1),")")

_ArrayAdd($Sorted,$1)

_ArrayDisplay($Sorted,"Sorted")

_ArrayDelete($avCRanking,$i)

$i=$i-1

Else

$i=$i-1

EndIf

Until _ArrayMax($avCRanking,1) = 0

---------------------------------------------------------

ERROR:

--------------------------------

TestScript.au3 (20) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

If _ArrayMax($avCRanking,1) = $avCRanking[$i] Then

If _ArrayMax($avCRanking,1) = ^ ERROR

---------------------------------

Thanks in advance!

Share this post


Link to post
Share on other sites



Once you delete the last element it is no longer an array

from help file _ArrayDelete

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

Suggest you have if (IsArray($avCRanking)) then statement in your code to check if it is still an array.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Once you delete the last element it is no longer an array

from help file _ArrayDelete

Suggest you have if (IsArray($avCRanking)) then statement in your code to check if it is still an array.

<{POST_SNAPBACK}>

Thanks for the help!

I have reread the help file and the statement reads.

Deletes the specified element from the given array, returning the adjusted array.

The key here is [B]"returning the adjusted array"[/B]

I have included a Test.ini Below and the Test script code, 

Test.ini
----------------------------------------
[TestSection]
P1 = 11
P2 = 34
P3 = 22
P4 = 14
P5 = 7
P6 = 10
P7 = 15
P8 = 9
P9 = 16
P10 =12
P11 = 3
P12 = 17
P13 = 211
P14 = 334
P15 = 119
P16 = 418
P17 = 620
P18 = 111
P19 = 5648
P20 = 2122

;Testing Script

#include <Array.au3>

Dim $i, $1, $var, $avCRanking[1],$Sorted[1]

$var = IniReadSection("Test.ini", "TestSection")

For $i=1 To $Var[0][0]

_ArrayAdd($avCRanking, $var[$i][1])

Next

_ArrayDisplay($avCRanking," ")

$i=UBound($avCRanking)-1

Do

If _ArrayMax($avCRanking,1) = $avCRanking[$i] Then

$1=StringFormat("%s%s%s%s",$i,"(",_ArrayMax($avCRanking,1),")")

_ArrayAdd($Sorted,$1)

_ArrayDisplay($Sorted,"Sorted")

_ArrayDelete($avCRanking,$i)

$i=$i-1

Else

$i=$i-1

EndIf

Until _ArrayMax($avCRanking,1) = 0

Share this post


Link to post
Share on other sites

I have figured out why the error was occuring.

$i was not getting reset in the inner If statement.

was > $i=$i+1

needed > $i=0

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  
Followers 0