Sign in to follow this  
Followers 0
Swimming_Bird

_ArraySearch Not working with my implementation

10 posts in this topic

#1 ·  Posted (edited)

I'm trying to do just a basic search but i get errors, when i have $i_Base=0 i get @error=2 = $iKey is out of bounds.

When i have $i_Base=1 it errors out while loading with this error:

C:\Program Files\AutoIt3\Include\Array.au3 (56) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

If $avArray[$iLwrLimit]> $sKey Or $avArray[$iUprLimit] < $sKey Then

If ^ ERROR

For $n = 1 To $addons[0]
    If _ArrayBinarySearch ( $currentaddons , $addons[$n] , 0 ) <> '' Then
        Local $onlineversion
        Local $localversion
        $onlineversion = IniRead ( 'Addon.ini' , $addons[$n] , 'Version' , 9999 )
        $localversion = IniRead ( $addondir & 'CurrentAddons.ini' , $addons[$n] , 'Version' , 0 )
        MsgBox ( 0 , '' , 'Online Version: ' & $onlineversion & ' Local Version: ' & $localversion )
        If $onlineversion < $localversion Then
            $color[$n] = 1
        Else
            $color[$n] = 0
        EndIf
    EndIf
    MsgBox ( 0 , 'Error' , @error )
Next

$currentaddons

[0] = CTRAmod

$addons:

[0] = 12
[1] = CastParty
[2] = CT_MailMod
[3] = CT_RABossMods
[4] = CT_RaidAssist
[5] = CT_RaidTracker
[6] = GoodInspect
[7] = ItemRack
[8] = ScrollingCombatText
[9] = SpellDPS
[10]    = DamageMeters
[11]    = ShardTracker
[12]    = CTRAmod

All help will be greatly appreciated,

Thanks

Edited by Swimming_BIrd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Is $currentaddons an array? Below you have it only containing one variable, is it possible that it is not declared as an array. Can you post full script?

EDIT: Forgot something.

Edited by Don N

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites

here's the whole thing

$currentaddons is definately an array, in this case it's only got one string in it in this case but im building it to work when the array is empty or has many entries.

Share this post


Link to post
Share on other sites

also, why isnt the [autoit] tag working for me?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

there are 2 issues here:

1. your if is wrong. You either test for the @error returned or like i did in the below example.

2. _ArrayBinarySearch has an test that forces you to have an Array with at least 2 entries. Will change the Official UDF to the below version with the next upload.

autoit tags are temporarily disabled because of forum/website issues....

:D

Dim $currentaddons[1]
Dim $addons[13]
$currentaddons[0]   = "CTRAmod"
$addons[0]  = 12
$addons[1]  = "CastParty"
$addons[2]  = "CT_MailMod"
$addons[3]  = "CT_RABossMods"
$addons[4]  = "CT_RaidAssist"
$addons[5]  = "CT_RaidTracker"
$addons[6]  = "GoodInspect"
$addons[7]  = "ItemRack"
$addons[8]  = "ScrollingCombatText"
$addons[9]  = "SpellDPS"
$addons[10] = "DamageMeters"
$addons[11] = "ShardTracker"
$addons[12] = "CTRAmod"

For $n = 1 To $addons[0]
    If Not (_ArrayBinarySearch ( $currentaddons, $addons[$n],0 ) == '') Then 
        ConsoleWrite('@@ Found:' & $addons[$n] & @lf);### Debug Console
    EndIf
Next

Func _ArrayBinarySearch(ByRef $avArray, $sKey, $i_Base = 0)
    Local $iLwrLimit = $i_Base
    Local $iUprLimit
    Local $iMidElement
    
    If (Not IsArray($avArray)) Then
        SetError(1)
        Return ""
    EndIf
    $iUprLimit = UBound($avArray) - 1
    $iMidElement = Int( ($iUprLimit + $iLwrLimit) / 2)
; sKey is smaller than the first entry
    If $avArray[$iLwrLimit] > $sKey Or $avArray[$iUprLimit] < $sKey Then
        SetError(2)
        Return ""
    EndIf
    
    While $iLwrLimit <= $iMidElement And $sKey <> $avArray[$iMidElement]
        If $sKey < $avArray[$iMidElement] Then
            $iUprLimit = $iMidElement - 1
        Else
            $iLwrLimit = $iMidElement + 1
        EndIf
        $iMidElement = Int( ($iUprLimit + $iLwrLimit) / 2)
    WEnd
    If $iLwrLimit > $iUprLimit Then
; Entry not found
        SetError(3)
        Return ""
    Else
;Entry found , return the index
        SetError(0)
        Return $iMidElement
    EndIf
EndFunc ;==>_ArrayBinarySearch
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Answer in above post...

EDIT: JdeB is quicker

Edited by Don N

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites

Thanks a lot for the help.

Just out of curiocity what line in the modified function did you change to allow for an array that is smaller then 2?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks a lot for the help.

Just out of curiocity what line in the modified function did you change to allow for an array that is smaller then 2?

Nope. Your If fails when the returned entry is the first entry in the Array. The UDF will then return a 0.

If 0 <> '' Then is also False and thus wrong.

I have removed a few lines that did a test for the number of entries in the Array which weren't needed since there is already a test for a valid array at the beginning of the UDF.

:D

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

autoit tags are temporarily disabled because of forum/website issues....

:D

That sucks! Edited by AutoItKing

http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script]

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