algiuxas

[Solved] ArraySearch doesn't work when using $array[0] = 0

6 posts in this topic

#1 ·  Posted (edited)

Hello everybody, so I might found a bug in _ArraySearch:
 

#include <Array.au3>
Local $abc[2] = ["b", "b"]
$h = "+---------------------------------+" & @CRLF
ConsoleWrite($h)
For $i = 0 To 1
    $abc[0] = 0
    out()
    $abc[0] = 1
    out()
    $abc[0] = -1
    out()
    $abc[0] = "Abc"
    out()
    $abc[1] = "Hello"
Next
Func txt()
    Return "$abc = [" & $abc[0] & ", " & $abc[1] & "]" & @CRLF & _
            "> _ArraySearch($abc,""Hello"") = "
EndFunc   ;==>txt
Func shouldoutput($ans)
    Return "_ArraySearch Should return:  " & ($ans ? 1 : -1)
EndFunc   ;==>shouldoutput
Func out()
    ConsoleWrite("> " & txt() & _ArraySearch($abc, "Hello") & @CRLF & "> " & shouldoutput($abc[1] == "Hello") & @CRLF & $h)
EndFunc   ;==>out
Exit

Sorry for this messy script

Edited by algiuxas

42783.png

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

8 minutes ago, algiuxas said:

 

Edited by MattHiggs

Share this post


Link to post
Share on other sites
2 minutes ago, MattHiggs said:

 

That says a lot.


42783.png

Share this post


Link to post
Share on other sites
10 minutes ago, algiuxas said:

Hello everybody, so I might found a bug in _ArraySearch:
 

#include <Array.au3>
Local $abc[2] = ["b", "b"]
$h = "+---------------------------------+" & @CRLF
ConsoleWrite($h)
For $i = 0 To 1
    $abc[0] = 0
    out()
    $abc[0] = 1
    out()
    $abc[0] = -1
    out()
    $abc[0] = "Abc"
    out()
    $abc[1] = "Hello"
Next
Func txt()
    Return "$abc = [" & $abc[0] & ", " & $abc[1] & "]" & @CRLF & _
            "> _ArraySearch($abc,""Hello"") = "
EndFunc   ;==>txt
Func shouldoutput($ans)
    Return "_ArraySearch Should return:  " & ($ans ? 1 : -1)
EndFunc   ;==>shouldoutput
Func out()
    ConsoleWrite("> " & txt() & _ArraySearch($abc, "Hello") & @CRLF & "> " & shouldoutput($abc[1] == "Hello") & @CRLF & $h)
EndFunc   ;==>out
Exit

Sorry for this messy script

Yeah, I can't even begin to interpret what you are trying to accomplish here.  But first thing that needs to be clarified is WHICH parameter you believe is throwing the error when set to 0.  But even given that, I notice that your _Arraysearch function uses the default values in the script you provided, so I am not sure what you are saying is broken.

Share this post


Link to post
Share on other sites
Just now, MattHiggs said:

Yeah, I can't even begin to interpret what you are trying to accomplish here.  But first thing that needs to be clarified is WHICH parameter you believe is throwing the error when set to 0.  But even given that, I notice that your _Arraysearch function uses the default values in the script you provided, so I am not sure what you are saying is broken.

+---------------------------------+
> $abc = [0, b]
> _ArraySearch($abc,"Hello") = 0
> _ArraySearch Should return:  -1
+---------------------------------+
> $abc = [1, b]
> _ArraySearch($abc,"Hello") = -1
> _ArraySearch Should return:  -1
+---------------------------------+
> $abc = [-1, b]
> _ArraySearch($abc,"Hello") = -1
> _ArraySearch Should return:  -1
+---------------------------------+
> $abc = [Abc, b]
> _ArraySearch($abc,"Hello") = -1
> _ArraySearch Should return:  -1
+---------------------------------+
> $abc = [0, Hello]
> _ArraySearch($abc,"Hello") = 0
> _ArraySearch Should return:  1
+---------------------------------+
> $abc = [1, Hello]
> _ArraySearch($abc,"Hello") = 1
> _ArraySearch Should return:  1
+---------------------------------+
> $abc = [-1, Hello]
> _ArraySearch($abc,"Hello") = 1
> _ArraySearch Should return:  1
+---------------------------------+
> $abc = [Abc, Hello]
> _ArraySearch($abc,"Hello") = 1
> _ArraySearch Should return:  1
+---------------------------------+

You can see it returns incorrectly when the first array value is 0.


42783.png

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Sometimes it would help when one first dumb things down to the basics to show their issue. ;)

Have a look at this and see if you can figure out why you get your "error":

#include <Array.au3>
Local $abc[2] = [0, 1]
ConsoleWrite('_ArraySearch($abc, "ABC") = ' & _ArraySearch($abc, "ABC") & ' >Error code: ' & @error & @CRLF)
ConsoleWrite('_ArraySearch($abc, 0) = ' & _ArraySearch($abc, 0) & ' >Error code: ' & @error & @CRLF)
ConsoleWrite('_ArraySearch($abc, 1) = ' & _ArraySearch($abc, 1) & ' >Error code: ' & @error & @CRLF)
ConsoleWrite('_ArraySearch($abc, "ABC", Default, Default, Default, 3) = ' & _ArraySearch($abc, "ABC", Default, Default, Default, 3) & ' >Error code: ' & @error & @CRLF)
ConsoleWrite('_ArraySearch($abc, 0, Default, Default, Default, 3) = ' & _ArraySearch($abc, 0, Default, Default, Default, 3) & ' >Error code: ' & @error & @CRLF)
ConsoleWrite('_ArraySearch($abc, 1, Default, Default, Default, 3) = ' & _ArraySearch($abc, 1, Default, Default, Default, 3) & ' >Error code: ' & @error & @CRLF)

Jos

Edited by Jos
1 person likes this

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

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

  • Similar Content

    • ronmage
      By ronmage
      So I have a loop that keeps reading data from an array and searching it for the same value. If the value is no there it does work then adds the value to the array to prevent it from doing the same work.
      If _ArraySearch($ID,$filearray[$i]) = -1 Then Work.... _ArrayAdd($ID,$filearray[$i]) EndIf This is in a for loop hence $i
      So what is happening is the code works great for several hours. After a period of time _ArraySearch($ID,$filearray[$i]) will result in -1 even if $ID = $filearray. So it ready as if there is no data in the array. Anyone have this problem? 
       
      Also I am just running in using F5 not compiling it and running it if that makes a difference.
       
    • Ascer
      By Ascer
      1. Description.
      Udf working with MSDN System.Collections.ArrayList. Allow you to make fast operations on huge arrays, speed is even x10 better than basic _ArrayAdd.  Not prefered for small arrays < 600 items. 2. Requirements
      .NET Framework 1.1+ System Windows 3. Possibilities.
      ;=============================================================================================================== ; UDF Name: List.au3 ; ; Date: 2018-02-17, 10:52 ; Description: Simple udf to create System Collections as ArrayList and make multiple actions on them. ; ; Function(s): _ListCreate -> Creates a new list ; _ListCapacity -> Gets a list size in bytes ; _ListCount -> Gets items count in list ; _ListIsFixedSize -> Get bool if list if fixed size ; _ListIsReadOnly -> Get bool if list is read only ; _ListIsSynchronized -> Get bool if list is synchronized ; _ListGetItem -> Get item on index ; _ListSetItem -> Set item on index ; ; _ListAdd -> Add item at end of list ; _ListClear -> Remove all list items ; _ListClone -> Duplicate list in new var ; _ListContains -> Get bool if item is in list ; _ListGetHashCode -> Get hash code for list ; _ListGetRange -> Get list with items between indexs ; _ListIndexOf -> Get index of item ; _ListInsert -> Insert a new item on index ; _ListInsertRange -> Insert list into list on index ; _ListLastIndexOf -> Get index last of item ; _ListRemove -> Remove first found item ; _ListRemoveAt -> Remove item in index ; _ListRemoveRange -> Remove items between indexs ; _ListReverse -> Reverse all items in list ; _ListSetRange -> Set new value for items in range ; _ListSort -> Sort items in list (speed of reading) ; _ListToString -> Get list object name ; _ListTrimToSize -> Remove unused space in list ; ; Author(s): Ascer ;=============================================================================================================== 4. Downloads
      List.au3 5. Examples
      SpeedTest _ArrayAdd vs ListAdd SpeedTest ArraySearch vs ListIndexOf Basic usage - crating guild with members  
    • FMS
      By FMS
      Hello,
      I'm trying to read a binary file to an array but couln't get it to work.
      Also I coul not find any help in the forum around this subject whish was helpfull.
      Is there any way it could be done?
      I tried a lot of ways but maybe somebody know's the right way?
      #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <File.au3> #include <Array.au3> #include <AutoItConstants.au3> Local $in=FileOpen("TEST_labels.idx1-ubyte",16) ; 16+0=Read binary Local $data = FileRead($in) Local $FileArray = BinaryToString($data,4) ;~ $FileArray = StringSplit($BinarydData, @CRLF, 1+2) ;~ Local $FileArray = StringRegExp($BinarydData, "[^\r\n]+", 3) FileClose($in) _ArrayDisplay($FileArray,"$FileArray","",32) MsgBox($MB_SYSTEMMODAL, "", "$FileArray = " & $FileArray )  
      TEST_labels.idx1-ubyte
    • dadalt95
      By dadalt95
      Perform a simple google search!
      The script below works fine until fill the google form!
      What I can't find is how to submit the form, tried a couple of ways and none of them worked.

       
      #include <IE.au3> $oIE = _IECreate ("www.google.com") $o_form = _IEFormGetObjByName ($oIE, "f") $o_login = _IEFormElementGetObjByName ($o_form, "q") $username = "80251369" _IEFormElementSetValue ($o_login, $username) $o_numer = _IEGetObjByName($o_form, "btnK") _IEAction ($o_numer, "click")  
      The code runs without any problem.
      I don't know how to proceed!
      Thanks in advance!
    • nacerbaaziz
      By nacerbaaziz
      Hi dears
      how are you? I hope You fine
      I have a question please
      I've created a listView
      It has several columns
      Is there any way  to search for text in an element of this list with text in all columns
      for example
      list view with 2 column
      the first is the file name and the second is the file path
      and i want to search for the item witch Containt the name and the path toGether
      I searched a lot but could not find what I was looking for
      If you do not understand the idea that I'm looking for, I can put an example
      Thanks in advance