Tomoya Posted July 5, 2011 Share Posted July 5, 2011 Do you guys know anyway to check if a value is in an array? I want it to check it against all the current array values but cant for the life of me figure out how, so I though I would ask the wise people of autoit forums. Link to comment Share on other sites More sharing options...
jaberwacky Posted July 5, 2011 Share Posted July 5, 2011 (edited) _arraySearch() Don't forget to put #Include <Array.au3> somewhere at the top of your script. If the array is sorted then you can use _ArrayBinarySearch() _ArrayFindAll() will return all of the indices of the value that you wish to find. Edited July 5, 2011 by LaCastiglione Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Tomoya Posted July 5, 2011 Author Share Posted July 5, 2011 _arraySearch()Dear lord please some one delete this thread before everyone finds out how much of a idiot I am ><I can't believe I missed that... Link to comment Share on other sites More sharing options...
czardas Posted July 5, 2011 Share Posted July 5, 2011 (edited) There are different methods. Here's a method that uses a for loop: Local $asArray[5] = ["one","two","three","four","five"] For $i = 0 To 4 If $asArray[$i] = "four" Then ExitLoop Next If $i < 5 Then MsgBox(0, "FOUND", "four was found at element " & $i) Edited July 5, 2011 by czardas operator64Â Â ArrayWorkshop Link to comment Share on other sites More sharing options...
jaberwacky Posted July 5, 2011 Share Posted July 5, 2011 This thread shall serve as a beacon for all future seekers. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Tomoya Posted July 6, 2011 Author Share Posted July 6, 2011 (edited) Had another question about the _ArraySearch function. I see that in the example they use @error to determine if its there or not and then display the msgbox... $iIndex = _ArraySearch($avArray, $sSearch, 0, 0, 0, 1) If @error Then MsgBox(0, "Not Found", '"' & $sSearch & '" was not found in the array.') Else MsgBox(0, "Found", '"' & $sSearch & '" was found in the array at position ' & $iIndex & ".") EndIf So I tried this Func ReIP() MouseClick("left", 1404, 881) MouseClick("left", 1302, 768) Sleep(1000) MouseClick("left", 299, 370) Sleep(2000) MouseClick("left", 239, 263) Sleep(5000) Send("^w") Sleep(10000) GetIP() EndFunc Func GetIP() $PublicIP = _GetIP() ;Gets the WAN IP GUICtrlSetData($IPList, $PublicIP) ;Updates the list to add the current IP Dim $IP_list ;Defining var For $x = 0 To _GUICtrlListBox_GetCount ($IPList) - 1 ;Starting check for array / adding to array If Not IsArray($IP_list) Then Dim $IP_list[1] Else ReDim $IP_list[UBound($IP_list) + 1] EndIf $IP_list[UBound($IP_list) - 1] = _GUICtrlListBox_GetText ($IPList, $x) Next _ArraySearch($IP_list, $PublicIP) ;Searching the array If @error Then ;This should come back as @error if the value is not there and click the location MouseClick("left", 1303, 70) Else ;This should be done if the value is there thus starting the proccess all over. ReIP() EndIf EndFunc And it just continuously loops the ReIP(). What it seems like is that it never @errors even when the IP is not the same, am I doing something wrong? Edited July 6, 2011 by Tomoya Link to comment Share on other sites More sharing options...
sleepydvdr Posted July 6, 2011 Share Posted July 6, 2011 Would changing these two lines help? $search = _ArraySearch($IP_list, $PublicIP) ;Searching the array If $search = "" Then ;This should come back as @error if the value is not there and click the location #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
Tomoya Posted July 6, 2011 Author Share Posted July 6, 2011 Would changing these two lines help? $search = _ArraySearch($IP_list, $PublicIP) ;Searching the array If $search = "" Then ;This should come back as @error if the value is not there and click the location So if $search = @error? That makes sense, I will try it and see what happens. They may have had something like this in the example script and I missed it. Link to comment Share on other sites More sharing options...
Tomoya Posted July 6, 2011 Author Share Posted July 6, 2011 This thread shall serve as a beacon for all future seekers. Double post but I thought the answer was worth it... I solved my problem by using this function to add the current IP to an array if it was a new IP that was not already in the array. Enjoy. Thanks everyone for the help. Func CheckIP() $PublicIP = _GetIP() ;Gets the WAN IP If $PublicIp = -1 Then $PublicIP = _GetIP() Else GUICtrlSetData($IPList, $PublicIP) ;Updates the list to add the current IP _ArrayDisplay($IP_list) $Location = _ArraySearch($IP_list, $PublicIP) ;Searching the array If @error Then MsgBox(0, "Not Found", '"' & $PublicIP & '" was not found in the array.') _ArrayAdd($IP_list, $PublicIP) Else MsgBox(0, "Found", '"' & $PublicIP & '" was found in the array at position ' & $Location & ".") EndIf EndIf EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now