Jump to content

_ArraySearch Not working with my implementation


Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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]
Link to comment
Share on other sites

  • Developers

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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