Jump to content

_ArraySearch($array, $var1 & $var2 & $var3, 0, 0, 0, 2, 1, 1) Help


Recommended Posts

Hi guys. Im using an array search for 3 variables.

I then want my output to tell me which variable or variables do not exsist without having to hard code a search or a messagebox for each variable

_ArraySearch($array, $var1 & $var2 & $var3, 0, 0, 0, 2, 1, 1)

if @error then

which variable does not exsits in the arraysearch

Sorry if this doesnt make sence. Im still learning the coding langue

 Regards

Link to post
Share on other sites

A loop is pretty much exactly for:

 

without having to hard code a search or a messagebox for each variable

 

I rolled a function that seems to meet the requirement.  This is a rare occasion in which you are receiving code whilst providing none because its easier to show than explain (for me).

#include <Array.au3>

Global $array[3] = ["var1", "var2" , "var3"]

msgbox(0, '' , _ArraySearchEx($array, "var0,var1,var2,var3,var4"))

Func _ArraySearchEx($array , $sSearch)

$string = ""
$aSearch = stringsplit($sSearch , "," , 3)

for $i = 0 to ubound($aSearch) - 1
    $sMatch = _ArraySearch($array , $aSearch[$i])
    If $sMatch <> - 1 Then
        $string &= $aSearch[$i] & " was found at index " & $sMatch & @CRLF
    Else
        $string &= $aSearch[$i] & " was not found" & @CRLF
    EndIf
Next

return $string

EndFunc

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...