Hi zusammen,
folgende Problematik:
Ich greife Nagios (Monitoring) Daten ab welche ich in einer Listview abbilde.
Habe dann eine Updatefunktion welche alle Items die in der Listview sind mit Host|Nachricht in ein 2D Array klatscht.
im selben moment wird in ein anderes 2 Array mit Host|Nachricht die neuen Nagios Nachrichten geschrieben.
Jetzt vergleiche ich beide auf unterschiede damit ich die Listview dann leeren kann und neu auffüllen bei unterschieden.
Klappt alles super, würde nur gerne genau wisssen welche Items neu dazugekommen sind.
Das gibt die Funktion leider nicht her.
Bekomme bei einem Unterschied lediglich "-1" und die Anzahl der Elemente:
Example #2: in case the arrays sizes are different: $a1 size = 3x2 , $a2 size = 1x2
; the return array will be:
; +---+---+---+
; | -1|3x2|1x2|
; +---+---+---+
Jemand eine Idee?
Danke !
; #FUNCTION# ====================================================================================================================
; Name ..........: _Array_Compare2D
; Description ...: Compares the first two diemnsions of two input arrays.
; Syntax.........: _Array_Compare2D($a1,$a2)
; Parameters ....: $a1,$a2 - two 2D arrays.
; Return values .: An array of size [n+1][3], where n is the number of differences, and the columns are:
; rows 1..n:
; cell position (zero-based) | value in $a1 | value in $a2
; row 0:
; cell [0][0] holds the number of differences, 0 means no differences, -1 means some mismatch between the arrays sizes or dimensions.
; cell [0][1] holds the sizes of dimensions of $a1 (only 1st two dimentions)
; cell [0][2] holds the sizes of dimensions of $a2 (only 1st two dimentions)
; an array is always returned, even when an error occurs - see "Remarks" section hereunder.
; Author ........: orbs
; Modified ......:
; Remarks .......: input variables, 1D arrays, or arrays different in sizes, are handled as described in the "Return values" section above, also see Exmple #2 hereunder
; to use this function as boolean indication (arrays are either identical or not), check cell [0][0] of the return array:
; arrays are identical only when cell [0][0] holds 0.
; Example #1: in case the arrays are of size 8x7 and are identical except of:
; $a1[3][1]='ABC' and $a2[3][1]='DEF'
; $a1[5][6]='123' and $a2[5][6]='456'
; the return array will be:
; +---+---+---+
; | 2 |8x7|8x7|
; +---+---+---+
; |3x1|ABC|DEF|
; +---+---+---+
; |5x6|123|456|
; +---+---+---+
; Example #2: in case the arrays sizes are different: $a1 size = 3x2 , $a2 size = 1x2
; the return array will be:
; +---+---+---+
; | -1|3x2|1x2|
; +---+---+---+
; note: 1D array of size 3 will be noted as 3x0, a variable will be noted as an array of size 0x0
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _Array_Compare2D($a1, $a2)
; declare
Local $a3[1][3] ; will be filled and returned <<<<<<<<<<< Don't use Dim
Local $n = 0 ; the number of differences
Local $i, $j ; loop index variables
; init
$a3[0][0] = 0
$a3[0][1] = UBound($a1, 1) & 'x' & UBound($a1, 2)
$a3[0][2] = UBound($a2, 1) & 'x' & UBound($a2, 2)
; precheck sizes and dimensions
;~ If UBound($a1, 2) = 0 Or _ ; $a1 is 1D array
;~ UBound($a2, 2) = 0 Or _ ; $a2 is 1D array
;~ UBound($a1, 3) > 0 Or _ ; $a1 is 3D array or more
;~ UBound($a2, 3) > 0 Or _ ; $a2 is 3D array or more
;~ UBound($a1, 1) <> UBound($a2, 1) Or _ ; size of 1st dimension is different
;~ UBound($a1, 2) <> UBound($a2, 2) Then ; size of 2nd dimension is different
;~ $a3[0][0] = -1
;~ Return $a3
;~ EndIf
If UBound($a1, 0) <> 2 Or (Ubound($a1, 1) <> Ubound($a2, 1)) Or (Ubound($a1, 2) <> Ubound($a2, 2)) Then
$a3[0][0] = -1
Else
; compare
For $i = 0 To UBound($a1, 1) - 1
For $j = 0 To UBound($a1, 2) - 1
If $a1[$i][$j] <> $a2[$i][$j] Then
$n += 1
If $n >= UBound($a3, 1) Then ReDim $a3[$n + 1000][3] ; Don't ReDim so often, large arrays would seriously slow this down otherwise
$a3[0][0] = $n
$a3[$n][0] = $i & 'x' & $j
$a3[$n][1] = $a1[$i][$j]
$a3[$n][2] = $a2[$i][$j]
EndIf
Next
Next
ReDim $a3[$n][3]
EndIf
; return
Return $a3
EndFunc ;==>_Array_Compare2D
Alles anzeigen