Jump to content
Sign in to follow this  
Tomoya

Array Check

Recommended Posts

Tomoya

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.

Share this post


Link to post
Share on other sites
jaberwacky

_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 by LaCastiglione

Share this post


Link to post
Share on other sites
Tomoya

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

Share this post


Link to post
Share on other sites
Tomoya

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 by Tomoya

Share this post


Link to post
Share on other sites
sleepydvdr

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>

Share this post


Link to post
Share on other sites
Tomoya

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.

Share this post


Link to post
Share on other sites
Tomoya

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.