Jump to content
Sign in to follow this  

how to compare 2 arrays

Recommended Posts


I use a foreach statements in TCL code, but have not figured out how to perform that process in Autoit. What I want to do is have a program which when a process starts, that the program will be able to act on it. but I want to use a list of programs to watch for.

TCL Code

proc AppProcessCheck {} {
                         SetErrorMode resume
                         SetTimeout 50msec
                         global _SSOERR
                 CloseWindows "*Internet Explorer*"
                         CloseWindows "*THR Mainframe*"
                         DisplayStatusBox "Checking for Open Applications" 
                         set user_apps {
                       set process_list_exe_name "tasklist.exe"    ;# from Windows install
                       set winuser "[GetWindowsUserName]"
                       set std_out ""
                             catch {set std_out [exec $process_list_exe_name /NH /FI "USERNAME eq texas\\$winuser"]}
                             set data [split $std_out "\n"]
                             foreach line $data {
                                  set endstrg [string first " " $line]
                                  set runapp [string range $line  0 [expr {$endstrg - 1}]]
                                  if {$runapp != ""} {
                                      foreach chkapp $user_apps {
                                      if {[string match -nocase "$runapp*" $chkapp]} {
                                        TerminateProcesses $runapp    

any help would be great, basically I looking to compare a static array and dynamic array and if I find a match then perform a task.

Share this post

Link to post
Share on other sites


Try looping _ArraySearch like this:

#include <Array.au3>

; This would be the list of processes you wished to act on
Global $aArray_Static[3] = ["Tom", "Dick", "Harry"]
; This would be the actual process list
Global $aArray_Dynamic[5] = ["Fred", "Dick", "Tom", "Bert", "Harry"]

For $i = 0 To UBound($aArray_Static) - 1

    If _ArraySearch($aArray_Dynamic, $aArray_Static[$i]) <> -1 Then

        MsgBox(0, "Found!", $aArray_Static[$i])  ; Do something with $aArray_Static[$i]



Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites


Thanks, that was easy (pushes the button)



Share this post

Link to post
Share on other sites



Func _ArrayCompare($ar1, $ar2)



dim $CommonItemsArray[1]


while($Array_i1< $ArrayCount_1)


While($Array_i2 < $ArrayCount_2)

if (StringInStr ($ar1[$Array_i1],$ar2[$Array_i2])) then






$Array_i1= $Array_i1+1



return $CommonItemsArray


Edited by ankushsingh

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.