Sign in to follow this  
Followers 0
RogFleming

how to compare 2 arrays

4 posts in this topic

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 {
                         IEXPLORE.EXE 
                         notepad.exe 
                         wordpad.exe
                         winword.exe
                         excel.exe
                         powerpnt.exe
                         acrord32.exe
                         Outlook.exe
                         wmplayer.exe 
                         MSACCESS.EXE
                         SeAM.exe
                         ess.exe
                         PFM.exe
                         FMReports.exe
                         CPhostpro.exe
                         wfront.exe
                         javaws.exe
                         javaw.exe
                         AtStaff.exe
                         costart.exe
                         VNEXPLORE.exe
                         IEExec.exe
                         DocNeTExplorer.exe
                         RoutingQueueView.exe
                         TRANSFER.exe
                         CVIEWER.exe
                         VNEXPLORE.exe
                         LISTDB.exe
                         Medstat.exe
                         carestat.exe
                         CU.exe
                         ExitCare.exe
                         Elig.exe
                         cvis0054.exe
                         SQStart.exe
                         ogu00.EXE
                         VIPRDE.exe
                         scguiw32.exe
                         fbkLoad.exe
                         Launch.exe
                         WDDspPag.Bin
                             XTND.EXE}
                       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    
                                        }
                                    }
                                }
                            }
                             return
                 }

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



RogFleming,

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]

    EndIf
Next

M23


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

Spoiler

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

Wow,

Thanks, that was easy (pushes the button)

Thanks,

Roger

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

IT WORKS FINE FOR ME

---------------------------------------------------------

Func _ArrayCompare($ar1, $ar2)

$ArrayCount_1=_ArraySize($ar1)

$ArrayCount_2=_ArraySize($ar2)

dim $CommonItemsArray[1]

$Array_i1=0

while($Array_i1< $ArrayCount_1)

$Array_i2=0

While($Array_i2 < $ArrayCount_2)

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

_ArrayAdd($CommonItemsArray,$ar2[$Array_i2])

ExitLoop

EndIf

$Array_i2=$Array_i2+1

WEnd

$Array_i1= $Array_i1+1

WEnd

_ArrayDelete($CommonItemsArray,0)

return $CommonItemsArray

Endfunc

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  
Followers 0