Jump to content
Sign in to follow this  
Champak

Array duplicate display need

Recommended Posts

Champak

I have an array that reads an ini section, sorts it, and displays it. I would like to do two other things in addition to what I have, but don't know how.

1/ Put duplicate values from the array into a variable to display somewhere else in my GUI

2/ Disregard modifier keys in the sorter. Meaning: the way things are now it will sort "^b", "+b" at the very beginning...before numbers and everything. I would like those to be sorted as if they didn't have the "^", "+", or "!". BUT, not be detected as duplicates to the regular "b".....but if there was a duplicate "^b" for instance, that would be detected. I hope that isn't confusing.

Here is my current code:

Global $STR
Func IniReadSort ()
    $STR = ""
    $ARRAY = IniReadSection($Where, "value")
    If @error Then
        MsgBox(4096, "Error occured", ", Error reading : App.ini file.")
        Exit
    Else
        _ArraySort($ARRAY, 0, 1, 0, 2, 1)
        For $a = 1 To $ARRAY[0][0]
            If (StringLen($STR) == 0) Then
                $STR = $ARRAY[$a][1]
            Else
                $STR = $STR & "  -  " & $ARRAY[$a][1]
            EndIf
        Next
    EndIf
EndFunc
IniReadSort()

The first one is more important.

Edited by Champak

Share this post


Link to post
Share on other sites
randallc

Hi,

1. Try using ArrayDupes3.zip in ArrayCompare post for displaying Dupes.

2. I think, to explain your needs best, you might need to atttach example "ini" file,

with required outcome file.

Best, Randall

Share this post


Link to post
Share on other sites
Champak

1/ Doesn't your script compare two separate arrays/files? I need to look in one ini file section/array and see if there are any duplicate values and display that....grab the array that I already have (first post - "$ARRAY") and search through that only for duplicate values, and display it as your script does.

2/ (If you mean explain number 2 clearer) - Let me know if you still need an ini file.

Let's say the values in a section (which are returned by my "$ARRAY") are:

!j, u, s, f, J, d, j, {F8}, +j, a, x, +d, {F9}

My script will return it as the following after being sorted: -- modifier keys->function keys->regular letters

+d, !j, +j, {F8}, {F9}, a, d, f, j, J, s, u, x

I would like it to come back as the following: -- notice the letter "d" and "j" with the modifier keys are lined up with the regular "d" and "j" instead of at the beginning like how my script already sorts it.

{F8}, {F9}, a, d, +d, f, j, J, !j, +j, s, u, x

Thanks

Edited by Champak

Share this post


Link to post
Share on other sites
randallc

Hi,

1. I'll look.

2. You might want subsort vbs;; or just get a 2D array, sort on col 4, the go back to 1D array, then strings..

[The closest output to requested was just sorting on col4 rather than then subsorting; but has to be case- insensitive too..]

; ArrayKeySort.au3
#include<array.au3>
Local $strkeys = "!j, u, s, f, J, d, j, {F8}, +j, a, x, +d, {F9}"
Local $arKeys = StringSplit($strkeys, ","),  $arTmp,$arKeys2[UBound($arKeys)]
_ArrayDelete($arKeys, 0)
For $i = 0 To UBound($arKeys) - 1
    $arTmp = StringSplit(StringFormat("%04s", $arKeys[$i]), "")
    $arKeys[$i] = _ArrayToString($arTmp, "|", 1)
Next
$arKeys2=$arKeys
$arKeys2[0]=$arKeys[0]
_SubSort($arKeys2, "4")
For $i = 0 To UBound($arKeys) - 1
    $arKeys2[$i] =StringReplace(StringReplace($arKeys2[$i],"|",""),"0","")
Next
_ArrayDisplay($arKeys2, "1D $arKeys2 - col 4 only ")
_SubSort($arKeys, "4|3")
For $i = 0 To UBound($arKeys) - 1
    $arKeys[$i] =StringReplace(StringReplace($arKeys[$i],"|",""),"0","")
Next
_ArrayDisplay($arKeys, "1D $arKeys2 sort on 4, subsort 3")

Func _SubSort(ByRef $arEither2D1D, $iIndex = "1",$iCase=0); 1D must be "|" delimited!
    Local $VBScode = 'function SubSort( byref arSingle,iIndex,icase)'
    $VBScode &= @LF & ' arIndexN=split(iIndex,"|")'
    $VBScode &= @LF & ' dim iAsc:iAsc=0'
    $VBScode &= @LF & ' if arIndexN(0)<0 then iAsc=1'
    $VBScode &= @LF & ' dim arIndex()'
    $VBScode &= @LF & ' redim preserve arIndex(1)'                                                                                                 ;:arIndex(1) =0
    $VBScode &= @LF & ' for a= 0 to ubound(arIndexN)'
    $VBScode &= @LF & '     arIndexN(a)=csng(arIndexN(a))'
    $VBScode &= @LF & '     if arIndexN(a)<>"" and arIndexN(a)<>0 then'
    $VBScode &= @LF & '         redim preserve arIndex(a)'
    $VBScode &= @LF & '         arIndex(a)=abs(arIndexN(a))-1'
    $VBScode &= @LF & '         arIndexN(a)=csng(Iif(arIndexN(a)<0,arIndexN(a)+1,arIndexN(a)-1))'
    $VBScode &= @LF & '     End If'
    $VBScode &= @LF & ' next'
    $VBScode &= @LF & ' ArraySort arSingle, iAsc,  0, UBound(arSingle), arIndex(0),icase  '                                                                                                 ;SortArray, iAsc,First, Last,iViewColNum
    $VBScode &= @LF & ' for indexcol=1 to ubound(arIndex)'                                                                                                 ;col=2'; start with check on 2nd  index'; define first index as col 1 (in call, 1)
    $VBScode &= @LF & '     SubSort1 arSingle,arIndex,indexcol,iif(arIndexN(indexcol)<0,-1,1),icase  '                                                                                                 ;->, sort order
    $VBScode &= @LF & ' Next'
    $VBScode &= @LF & ' SubSort=arSingle'
    $VBScode &= @LF & 'end function   '                                                                                                 ;==>ArrayFieldSort
    $VBScode &= @LF & 'function SubSort1(byref arArray,arIndex,indexcol, iAsc,icase)'
    $VBScode &= @LF & ' dim Row,col:col=arIndex(indexcol)'
    $VBScode &= @LF & ' dim pcol:pcol=arIndex(indexcol-1)'
    $VBScode &= @LF & ' iAsc=Iif(iAsc<0,1,0)'
    $VBScode &= @LF & ' dim arTemp(),itemp, sMarker:sMarker="Equal"'                                                                                                 ;,sTemp(1)
    $VBScode &= @LF & ' redim preserve arTemp(1) '                                                                                                 ;redim extra row
    $VBScode &= @LF & ' for Row=1 to UBound(arArray) '                                                                                                 ; go through all rows of 2d array in that column to check for dupes
    $VBScode &= @LF & '         arRow=split(arArray(row),"|")'
    $VBScode &= @LF & '         arRowB4=split(arArray(row-1),"|")'
    $VBScode &= @LF & '     if indexcol>1 then '                                                                                                 ;check cols in each row first if more than 2 index cols
    $VBScode &= @LF & '         for c=0 to indexcol-1'
    $VBScode &= @LF & '             if lcase(arRow(arIndex(c)))<>lcase(arRowB4(arIndex(c))) Then'
    $VBScode &= @LF & '                 sMarker="pColsNotEqual"'
    $VBScode &= @LF & '                 c=indexcol'
    $VBScode &= @LF & '             End If'
    $VBScode &= @LF & '         Next'
    $VBScode &= @LF & '     End If'
    $VBScode &= @LF & '     if lcase(arRow(pcol))=lcase(arRowB4(pcol)) and sMarker="Equal" Then '                                                                                                 ;dupes in the prev col.
    $VBScode &= @LF & '         arTemp(itemp)=arArray(row-1)'                                                                                                 ;Array2DToD( arArray2d,"",0,row-1,1) '; set first line of new potential sort array
    $VBScode &= @LF & '         redim preserve arTemp(itemp+1) '                                                                                                 ;redim extra row
    $VBScode &= @LF & '         arTemp(itemp+1)=arArray(row)'                                                                                                 ;Array2DToD( arArray2d,"",0,row-1,1) '; set first line of new potential sort array
    $VBScode &= @LF & '         itemp=itemp+1'
    $VBScode &= @LF & '     Else'
    $VBScode &= @LF & '         sMarker="Equal"'
    $VBScode &= @LF & '         SubSortDo1 arArray,arTemp,itemp,iAsc,col,row,icase'
    $VBScode &= @LF & '     End If'
    $VBScode &= @LF & ' Next'
    $VBScode &= @LF & ' SubSortDo1 arArray,arTemp,itemp,iAsc,col,row,icase'
    $VBScode &= @LF & 'end function   '
    $VBScode &= @LF & 'function SubSortDo1(byref arArray,byref arTemp,byref itemp,iAsc,col,row,icase)'
    $VBScode &= @LF & ' dim sTemp()'
    $VBScode &= @LF & ' if itemp>0 then'
    $VBScode &= @LF & '     ArraySort arTemp,  iAsc,0, UBound(arTemp), col ,icase'                                                                                                 ;sort on current col (pcol+1), asc?
    $VBScode &= @LF & '     for i= 0 to ubound(arTemp)'
    $VBScode &= @LF & '         arArray(row-ubound(arTemp)+i-1)=arTemp(i)'
    $VBScode &= @LF & '     Next'
    $VBScode &= @LF & ' End If'
    $VBScode &= @LF & ' redim preserve arTemp(1)'
    $VBScode &= @LF & ' itemp=0'                                                                                                 ; change backto single, then get into 2d array properly, then go on to check next line'; row=row-1??
    $VBScode &= @LF & ' SubSortDo1= SortArray'
    $VBScode &= @LF & 'end function'
    $VBScode &= @LF & 'Function IIf( expr, truepart, falsepart )'
    $VBScode &= @LF & '   IIf = falsepart'
    $VBScode &= @LF & '   If expr Then IIf = truepart'''
    $VBScode &= @LF & 'End Function'
    $VBScode &= @LF & 'function ArraySort(ByRef SortArray, iAsc,First, Last,iViewColNum,icase)'
    $VBScode &= @LF & ' dim strWrite,arCol,arColumn()'
    $VBScode &= @LF & ' ReDim Preserve arColumn(ubound(SortArray))'
    $VBScode &= @LF & ' Dim intPointer, booIsNumeric: booIsNumeric = True'
    $VBScode &= @LF & ' For intPointer = First To Last'
    $VBScode &= @LF & '     arCol = Split( SortArray(intPointer), "|", -1,0 )'
    $VBScode &= @LF & '     If Not IsNumeric( arCol(iViewColNum) ) Then'
    $VBScode &= @LF & '         booIsNumeric = False'
    $VBScode &= @LF & '         Exit For'
    $VBScode &= @LF & '     End If'
    $VBScode &= @LF & ' Next'
    $VBScode &= @LF & ' For intPointer = First To Last'
    $VBScode &= @LF & '     arCol = Split( SortArray(intPointer), "|", -1,0 )'
    $VBScode &= @LF & '     If booIsNumeric Then'
    $VBScode &= @LF & '         arColumn(intPointer)  = CSng( arCol(iViewColNum) )'
    $VBScode &= @LF & '     else'
    $VBScode &= @LF & '         arColumn(intPointer)  =  arCol(iViewColNum)'
    $VBScode &= @LF & '     End If'
    $VBScode &= @LF & ' Next'
    $VBScode &= @LF & ' if not icase then  QuickSortColumn  SortArray, arColumn,First, Last,iViewColNum'
    $VBScode &= @LF & ' if icase or booIsNumeric then QuickSortColumnCase  SortArray, arColumn,First, Last,iViewColNum'
    $VBScode &= @LF & ' if iasc=1 then ReverseElements SortArray, 0, ubound(SortArray)'
    $VBScode &= @LF & ' ArraySort= SortArray'
    $VBScode &= @LF & 'End function   '
    $VBScode &= @LF & 'function QuickSortColumn(ByRef SortArray, ByRef arColumn, First, Last,iViewColNum)'
    $VBScode &= @LF & ' dim Low,High,collitem,arCol'
    $VBScode &= @LF & ' dim Temp,ListSeparator'
    $VBScode &= @LF & ' Low = First'
    $VBScode &= @LF & ' High = Last'
    $VBScode &= @LF & ' ListSeparator=arColumn((First + Last) / 2)'
    $VBScode &= @LF & ' Do'
    $VBScode &= @LF & '     While lcase(arColumn(Low)) < lcase(ListSeparator)'
    $VBScode &= @LF & '         Low = Low + 1'
    $VBScode &= @LF & '     WEnd'
    $VBScode &= @LF & '     While lcase(arColumn(High)) > lcase(ListSeparator)'
    $VBScode &= @LF & '         High = High - 1'
    $VBScode &= @LF & '     WEnd'
    $VBScode &= @LF & '     If (Low <= High) Then'
    $VBScode &= @LF & '         Temp = SortArray(Low)'
    $VBScode &= @LF & '         SortArray(Low) = SortArray(High)'
    $VBScode &= @LF & '         SortArray(High) = Temp'
    $VBScode &= @LF & '         Temp = arColumn(Low)'
    $VBScode &= @LF & '         arColumn(Low) = arColumn(High)'
    $VBScode &= @LF & '         arColumn(High) = Temp'
    $VBScode &= @LF & '         Low = Low + 1'
    $VBScode &= @LF & '         High = High - 1'
    $VBScode &= @LF & '     End If'
    $VBScode &= @LF & ' Loop While (Low <= High)'
    $VBScode &= @LF & ' If (First < High) Then QuickSortColumn  SortArray, arColumn,First, High,iViewColNum '
    $VBScode &= @LF & ' If (Low < Last) Then QuickSortColumn  SortArray, arColumn,Low, Last,iViewColNum '
    $VBScode &= @LF & 'End function   '
    $VBScode &= @LF & 'function QuickSortColumnCase(ByRef SortArray, ByRef arColumn, First, Last,iViewColNum)'
    $VBScode &= @LF & ' dim Low,High,collitem,arCol'
    $VBScode &= @LF & ' dim Temp,ListSeparator'
    $VBScode &= @LF & ' Low = First'
    $VBScode &= @LF & ' High = Last'
    $VBScode &= @LF & ' ListSeparator=arColumn((First + Last) / 2)'
    $VBScode &= @LF & ' Do'
    $VBScode &= @LF & '     While (arColumn(Low) < ListSeparator)'
    $VBScode &= @LF & '         Low = Low + 1'
    $VBScode &= @LF & '     WEnd'
    $VBScode &= @LF & '     While (arColumn(High) > ListSeparator)'
    $VBScode &= @LF & '         High = High - 1'
    $VBScode &= @LF & '     WEnd'
    $VBScode &= @LF & '     If (Low <= High) Then'
    $VBScode &= @LF & '         Temp = SortArray(Low)'
    $VBScode &= @LF & '         SortArray(Low) = SortArray(High)'
    $VBScode &= @LF & '         SortArray(High) = Temp'
    $VBScode &= @LF & '         Temp = arColumn(Low)'
    $VBScode &= @LF & '         arColumn(Low) = arColumn(High)'
    $VBScode &= @LF & '         arColumn(High) = Temp'
    $VBScode &= @LF & '         Low = Low + 1'
    $VBScode &= @LF & '         High = High - 1'
    $VBScode &= @LF & '     End If'
    $VBScode &= @LF & ' Loop While (Low <= High)'
    $VBScode &= @LF & ' If (First < High) Then QuickSortColumnCase  SortArray, arColumn,First, High,iViewColNum '
    $VBScode &= @LF & ' If (Low < Last) Then QuickSortColumnCase  SortArray, arColumn,Low, Last,iViewColNum '
    $VBScode &= @LF & 'End function   '
    $VBScode &= @LF & 'Sub ReverseElements( arrToReverse, intAlphaRow, intOmegaRow )'
    $VBScode &= @LF & '    Dim intPointer, intUpper, intLower, varHolder'
    $VBScode &= @LF & '    For intPointer = 0 To Int( (intOmegaRow - intAlphaRow) / 2 )'
    $VBScode &= @LF & '        intUpper = intAlphaRow + intPointer'
    $VBScode &= @LF & '        intLower = intOmegaRow - intPointer'
    $VBScode &= @LF & '        varHolder = arrToReverse(intLower)'
    $VBScode &= @LF & '        arrToReverse(intLower) = arrToReverse(intUpper)'
    $VBScode &= @LF & '        arrToReverse(intUpper) = varHolder'
    $VBScode &= @LF & '    Next'
    $VBScode &= @LF & 'End Sub'
    Local $vbs = ObjCreate("ScriptControl")
    $vbs.language = "vbscript"
    $vbs.addcode($VBScode)
    $arEither2D1D = $vbs.Run("SubSort", $arEither2D1D, $iIndex,$iCase)
    $vbs = ""
EndFunc   ;==>_Array2D1DFieldSortSt
Edited by randallc

Share this post


Link to post
Share on other sites
randallc

1/ Doesn't your script compare two separate arrays/files? I need to look in one ini file section/array and see if there are any duplicate values and display that....grab the array that I already have (first post - "$ARRAY") and search through that only for duplicate values, and display it as your script does.

Hi,

I think I do need to see an example of your "ini",

with dupes, so I can see where the problem is.

Can you get them to a 1D array?

If so;

#include<ArrayDupes3.au3>
#include<_ArrayDisplaySort.au3>
Local $arFiles[4] = [@ScriptDir & "\hello.txt", @ScriptDir & "\goodbye.txt", @ScriptDir & "\adios.txt" , @ScriptDir & "\adios.txt"  ]
local $arDupes=_ArrayDupes( $arFiles,  1, 1);_ArrayDupes(byref $arrItemsF, $iDelete = 0, $iDetails = 0)
_ArrayDisplaySort($arDupes,"$arDupes|Item|Type|Element No.")

Alternatively, Are the "dupes" defined in 1 dimension of the 2D array, or both at once? [should still be able to get to 1D?]

Best, Randall

Edited by randallc

Share this post


Link to post
Share on other sites
Champak

I get the following code in trying your first script.

file.au3 (179) : ==> The requested action with this object has failed.: 
$vbs.addcode($VBScode) 
$vbs.addcode($VBScode)^ ERROR

================================================================

INI file looks like:

[Keys]

key1 = g
key2 = i
key3 = u
key4 = 5
key5 = w
key6 = u
key7 = G
key8 = p
key9 = a
key10 =2
key11 = w
......
......
......
......

[Strips]

.....
.....
.....

Side note: I don't want lowercase and caps to be considered dupes.

I don't understand what you are doing with the dupe thing in having four files in that array.

The section has about 30 entries, but dupes can happen anywhere in it. I can get the stuff in a 1D array, this is what I tried the other night...took me quite a few hours :D .

As a matter of fact this is what I tried....obviously it doesn't work the way I want it to, but you get the idea:

; ArrayCompareEx.au3
#include-once
#include <Array.au3>
#include <ArrayDupes3.au3>

$Where = IniReadSection("Grove.ini", "key")
dim $NewArray
dim $OriginalString = ""
dim $RemovedData
    $ARRAY = IniReadSection("Grove", "key")
    If @error Then
        MsgBox(4096, "Error occured", ", Error reading : file.")
        Exit
    Else
        _ArraySort($ARRAY, 0, 1, 0, 2, 1)
        For $I = 1 To $ARRAY[0][0]
            If (StringLen($OriginalString) == 0) Then
                $OriginalString = $ARRAY[$I][1]
            Else
                $OriginalString = $OriginalString & ',' & $ARRAY[$I][1]
            EndIf
        Next
    EndIf
    $NewArray = StringSplit($OriginalString,",")    
    $RemovedData = $NewArray
    $iCount = 0
    For $i = 0 To UBound($NewArray) - 1
        $iCount = 0
        For $ii = 0 To UBound($NewArray) - 1
            If $ii > UBound($RemovedData) - 1 Then ExitLoop
            If $RemovedData[$ii] = $NewArray[$i] Then
                If $iCount > 1 Then _ArrayDelete($RemovedData, $ii)
                $iCount += 2
            EndIf
        Next
    Next
 ;   Return $RemovedData    

_ArrayDisplay ($NewArray)
_ArrayDisplay ($RemovedData)

;$arr = StringSplit("Erez,Don,Know,To,Compare,1,x,6",",")

local $arAnsw=_ArrayCompare( $NewArray,  $RemovedData,1,1)
_ArrayDisplay ($arAnsw,"matched, no details",1,0,chr(1))

Thanks.

Edited by Champak

Share this post


Link to post
Share on other sites
randallc

Hi,

1. I have added to the zip in post #5; the script does not work when copied from the forum, but OK when downloaded!

2. Your script nearly works, and is working for me;;

$ARRAY = IniReadSection("Grove.ini", "Keys")

So what do you need to sort?; there are no "!d" things here?

Best, Randall

Share this post


Link to post
Share on other sites
Champak

I was just making a quick example, that's why there aren't any modifier keys, so here is another example:

[Keys]

key1 = g
key2 = g
key3 = g
key4 = 5
key5 = w
key6 = u
key7 = G
key8 = p
key9 = W
key10 =2
key11 = ^g
key12 = i
key13 = u
key14 = 5
key15 = +w
key16 = u
key17 = k
key18 = p
key19 = j
key20 = !w

[Strips]

.....
.....
.....

It works OK, except two things:

If there are multiple values that are the same (3 or more of the same value in the ini instead of just two) the code will return two or more of them, instead of just one--indicating that there is at least one double of this particular letter or number. I tried to run the dupes back through a regular "delete duplicates" code, but I couldn't get it.

Also, if there are no duplicate, an error happens in the script and shuts it down. The error is:

\AutoIt3\Include\ArrayDupes3.au3 (110) : ==> Array variable subscript badly formatted.: 
ReDim $arrItemsDupes[$k] 
ReDim $arrItemsDupes[^ ERROR
Edited by Champak

Share this post


Link to post
Share on other sites
randallc

Hi,

Maybe don't put the dupes in to start with..

; ArrayCompareEx2.au3
#include-once
#include <Array.au3>
#include <ArrayDupes3.au3>

$Where = IniReadSection("Grove.ini", "Keys")
Local $NewArray, $RemovedData
$ARRAY = IniReadSection("Grove.ini", "Keys")
If @error Then
    MsgBox(4096, "Error occured", ", Error reading : file.")
    Exit
Else
    _ArraySort($ARRAY, 0, 1, 0, 2, 1)
;~  _ArrayDisplay($ARRAY)
    Local $OriginalString = $ARRAY[1][1], $DupesString
    For $I = 1 To $ARRAY[0][0]
        If $ARRAY[$I][1] <> $ARRAY[$I - 1][1] Then
            $OriginalString &= ',' & $ARRAY[$I][1]
        Else
            $DupesString = StringReplace($DupesString, $ARRAY[$I][1]&",", "")  & $ARRAY[$I][1]& ','
        EndIf
    Next
EndIf
$arKeys = StringSplit($OriginalString, ",")
$RemovedData = StringSplit(StringTrimRight($DupesString,1), ",")
_ArrayDelete($RemovedData,0)
_ArrayDisplay($RemovedData,"$RemovedData")
Local $c = _ArrayDelete($arKeys, 0), $arTmp, $arKeys2[UBound($arKeys)], $ar2D[UBound($arKeys)][4]
_ArrayDisplay($arKeys)
;===================== Change to 2D          ============================
For $I = 0 To UBound($arKeys) - 1
    $arTmp = StringSplit(StringFormat("%04s", $arKeys[$I]), "")
    Local $iDiff = UBound($arTmp) - UBound($ar2D, 2)
    For $j = UBound($arTmp) - 1 To UBound($arTmp) - 4 Step - 1
        $ar2D[$I ][$j - $iDiff] = $arTmp[$j]
    Next
Next
;===================== Sort 2D   on Col4       ============================
_ArrayDisplay($ar2D, "2D $ar2D - col 4 only ")
_ArraySort($ar2D, 0, 0, 0, UBound($ar2D, 2), 3)
_ArrayDisplay($ar2D, "2D $ar2D - col 4 only ")
;===================== Change to 1D          ============================
For $I = 0 To UBound($ar2D) - 1
    For $j = 0 To UBound($ar2D, 2) - 1
        If $ar2D[$I ][$j] <> "0"  And $ar2D[$I ][$j] <> "" Then $arKeys2[$I] &= $ar2D[$I ][$j]
    Next
Next
_ArrayDisplay($arKeys2, "1D $arKeys2 - col 4 only ")
Best, Randall Edited by randallc

Share this post


Link to post
Share on other sites
Champak

That is BRILLIANT!!!!!! Making a 4 column array and then sort by the last column. You are good, I figured you would have just come up with some extra fancy code to factor in the modifiers, but instead you made it simple and elegant...nice.

I increased it to 7 columns to take into consideration the ENTER key.

A couple of problems though. - if you look in the script you'll see I put commented out numbers that will match up with what follows.

1/ Which ever value comes in the first row gets duplicated(Seen in 1). I put a delete function to take care of that, but if you know of a better way.

2/ I took both "0"s out at problem 2 and 3 because they were causing the script to delete a 0 if it was purposely set as a value. I see why you put the remove "0" in, but why did you put the "0"s in in the first place? Will there be a problem somewhere if I leave it how I modified it?

I don't understand what you mean by "Maybe don't put the dupes in to start with." If you mean to put an "IF" function in to check if there are values in the dupe array, I still get errors and it wont work. See what I tried and commented out at the bottom.

; ArrayCompareEx2.au3
#include-once
#include <Array.au3>
#include <ArrayDupes3.au3>

Dim $NewArray
Dim $OriginalString = ""
Dim $RemovedData
$ARRAY = IniReadSection("Grove.ini", "Keys")
If @error Then
    MsgBox(4096, "Error occured", ", Error reading : file.")
    Exit
Else
    _ArraySort($ARRAY, 0, 1, 0, 2, 1)
    ;~  _ArrayDisplay($ARRAY)
    $OriginalString = $ARRAY[1][1]
    For $I = 1 To $ARRAY[0][0]
        If $ARRAY[$I][1] <> $ARRAY[$I - 1][0] Then $OriginalString &= ',' & $ARRAY[$I][1]
    Next

    MsgBox(0,0,$OriginalString); --1-- the first row sorted gets duplicated
    $arKeys = StringSplit($OriginalString, ",")

    _ArrayDelete( $arKeys,1);I put this in to get rid of the duplicated first row

    _ArrayDisplay($arKeys)
    Local $c=_ArrayDelete($arKeys, 0), $arTmp, $arKeys2[UBound($arKeys)], $ar2D[UBound($arKeys)][7]; change column count
    ;_ArrayDisplay($arKeys)
    ;===================== Change to 2D          ============================
    For $i = 0 To UBound($arKeys) - 1
        $arTmp = StringSplit(StringFormat("%7s", $arKeys[$i]), ""); --2-- I took the "0" out of this because I think it was causing the 0s
        Local $iDiff = UBound($arTmp) - UBound($ar2D, 2)
        For $j = UBound($arTmp) - 1 To UBound($arTmp) - 7 Step - 1; change column count
            $ar2D[$i ][$j - $iDiff] = $arTmp[$j]
        Next
    Next
    ;===================== Sort 2D   on Col4       ============================
    ;_ArrayDisplay($ar2D, "2D $ar2D - col 4 only ")
    _ArraySort($ar2D, 0, 0, 0, UBound($ar2D,2), 6); change column count
    ;_ArrayDisplay($ar2D, "2D $ar2D - col 4 only ")
    ;===================== Change to 1D          ============================
    For $i = 0 To UBound($ar2D) - 1
        For $j = 0 To UBound($ar2D,2) - 1
            if $ar2D[$i ][$j]<>"" and $ar2D[$i ][$j]<>"" then $arKeys2[$i]&=$ar2D[$i ][$j]; --3-- took the "0" out from here to prevent the wanted 0 from being deleted
        Next
    Next
    ;_ArrayDisplay($arKeys2, "1D $arKeys2 - col 4 only ")


;Now checking for dupes
    For $I = 1 To $ARRAY[0][0]
            $OriginalString = $OriginalString & '|' & $ARRAY[$I][1]
    Next
    $NewArray = StringSplit($OriginalString,"|")


#cs -- I tried this to escape the error of an empty dupe array
    If _ArrayDupes($NewArray) == "" Then
        MsgBox(0,1,2)
        ;
    Else
        MsgBox(0,1,3)
    _ArrayDisplay(_ArrayDupes($NewArray))
    EndIf
#ce
#cs -- I also tried this to escape the error of an empty dupe array
    $no = _ArrayDupes($NewArray)
    ;_ArrayDisplay($no)
    If $no[0] == "" Then
        MsgBox(0,1,2)
        ;
    Else
        MsgBox(0,1,3)
    _ArrayDisplay(_ArrayDupes($NewArray))
    EndIf
#ce 
EndIf

Share this post


Link to post
Share on other sites
randallc

Hi,

I don't think you saw my modified post #9, and display "$RemovedData"

1. I agree about formatting with zeros ;and see my changes to attached script for the first ZDupe line

2. You don't need the check for dupes, as never added

If $ARRAY[$I][1] <> $ARRAY[$I - 1][0] Then

I have fixed the empty array dim error in Dupes5

Best, Randall

Share this post


Link to post
Share on other sites
Champak

Cool that's great. But now I see that the keys inside brackets like the function and enter keys don't get sorted. I tried doing a second array sort but obviously that doesn't work because it just resorts everything and messes up the initial sort. I did a search on this and it seems that others tried it with the exact same thing I did and they had success. Tell me if I'm doing it wrong or something please..you see it commented out below.

Also, I originally deleted you function to show dupes before because it considered lower and upper case dupes.

Dim $NewArray
Dim $OriginalString = ""
Dim $RemovedData
$ARRAY = IniReadSection("Grove.ini", "Key")
If @error Then
    MsgBox(4096, "Error occured", ", Error reading : file.")
    Exit
Else
    _ArraySort($ARRAY, 0, 1, 0, 2, 1)
    For $I = 1 To $ARRAY[0][0]
        If $ARRAY[$I][1] <> $ARRAY[$I - 1][0] Then $OriginalString &= $ARRAY[$I][1] & ','
    Next
    $OriginalString = StringTrimRight($OriginalString, 1)
    $ARRAY[0][0] = $OriginalString
    
    $arKeys = StringSplit($OriginalString, ",")

;   _ArrayDisplay($arKeys, "$arKeys")
    Local $c = _ArrayDelete($arKeys, 0), $arTmp, $arKeys2[UBound($arKeys)], $ar2D[UBound($arKeys)][7]; change column count
    ;_ArrayDisplay($arKeys)
    ;===================== Change to 2D          ============================
    For $I = 0 To UBound($arKeys) - 1
        $arTmp = StringSplit(StringFormat("%7s", $arKeys[$I]), "")
        Local $iDiff = UBound($arTmp) - UBound($ar2D, 2)
        For $j = UBound($arTmp) - 1 To UBound($arTmp) - 7 Step - 1; change column count
            $ar2D[$I ][$j - $iDiff] = $arTmp[$j]
        Next
    Next
    ;===================== Sort 2D   on Col4       ============================
;   _ArrayDisplay($ar2D, "2D $ar2D - col 4 only ")
    _ArraySort($ar2D, 0, 0, 0, UBound($ar2D, 2), 6); change column count
    _ArraySort($ar2D, 0, 0, 0, UBound($ar2D, 2), 6); Second sort to take care of function keys. Tried it with this before the one above..no go
;   _ArrayDisplay($ar2D, "2D $ar2D - col 4 only ")
    ;===================== Change to 1D          ============================
    For $I = 0 To UBound($ar2D) - 1
        For $j = 0 To UBound($ar2D, 2) - 1
            If $ar2D[$I ][$j] <> "" And $ar2D[$I ][$j] <> "" Then $arKeys2[$I] &= $ar2D[$I ][$j]
        Next
    Next
    _ArrayDisplay($arKeys2, "1D $arKeys2 - col 4 only ")


    ;Now checking for dupes
    For $I = 1 To $ARRAY[0][0]
        $OriginalString = $OriginalString & ',' & $ARRAY[$I][1]
    Next
    $NewArray = StringSplit($OriginalString, ",")

    $Dupes = _ArrayDupes($NewArray)
    If Not IsArray($Dupes) Or $Dupes[0] == "" Then
        ;MsgBox(0, 1, "No Dupes")
    Else
        _ArrayDisplay($Dupes)
    EndIf
EndIf

Thanks

Edited by Champak

Share this post


Link to post
Share on other sites
randallc

Cool that's great. But now I see that the keys inside brackets like the function and enter keys don't get sorted. others tried it with the exact same thing I did and they had success. .

I don't believe so ; show me for interest where you saw that; that is why I wanted to use my vbs subsort originally;

But you don't need to; try this at the end; [i see my plan for dupes is still wrong though; hard to see why at present, so maybe need dupes at end]

Edited by randallc

Share this post


Link to post
Share on other sites
randallc

Here it is again.. smaller!

#include <Array.au3>
#include <String.au3>
Dim $NewArray, $DupesString, $OriginalString, $RemovedData, $arSubSort[1], $sRev
Dim $ARRAY = IniReadSection("Grove.ini", "Keys")
If @error Then
    MsgBox(4096, "Error occured", ", Error reading : file.")
    Exit
EndIf
;===================== Reverse elements  for sort        ============================
For $I = 1 To $ARRAY[0][0]
    $ARRAY[$I][1] = _StringReverse($ARRAY[$I][1]);StringStripWS
Next
_ArraySort($ARRAY, 0, 1, 0, 2, 1)
_ArrayDisplay($ARRAY)
;===================== Reverse elements   Back   and to 1D, and arDupes    ============================
For $I = 1 To $ARRAY[0][0]
    $sRev = _StringReverse(String($ARRAY[$I][1]))& ","
    If StringInStr($OriginalString, $sRev , 1) Then 
        If Not StringInStr($DupesString, $sRev , 1) Then $DupesString &= $sRev 
    Else
        $OriginalString &= $sRev 
    EndIf
Next
$arKeys = StringSplit(StringTrimRight($OriginalString, 1), ",")
$RemovedData = StringSplit(StringTrimRight($DupesString, 1), ",")
_ArrayDisplay($RemovedData, "$RemovedData")
_ArrayDisplay($arKeys, "Final ** ")
Randall [Edit - note edited x1 "$OriginalString &= $sRev "] Edited by randallc

Share this post


Link to post
Share on other sites
Champak

Smaller...yet again I'm amazed.

There is yet another problem with showing the duplicates. Now

1/ A blank row, and a row with "1" gets inserted when there are no dupes.

2/ If there is a dupe, the dupes will show, but also a row with "1" gets inserted.

I have no idea what is happening with the code you made this time to even attempt to diagnose where that is coming from.

Thanks.

Share this post


Link to post
Share on other sites
randallc

Smaller...yet again I'm amazed.

There is yet another problem with showing the duplicates. Now

1/ A blank row, and a row with "1" gets inserted when there are no dupes.

2/ If there is a dupe, the dupes will show, but also a row with "1" gets inserted.

I have no idea what is happening with the code you made this time to even attempt to diagnose where that is coming from.

Thanks.

Hi,

I still have the problem that you and I are dealing with different ini files!

can you please post (ie attach to a post or PM me..) yours, as this is not happening to me.

best, randall

Edited by randallc

Share this post


Link to post
Share on other sites
Champak

OK, my error. The "1" that would show on the first row when there were dupes was indicating the amount of dupes in the array. So I just put an array delete to take care of that. And I did that with the array with no dupes to delete the row with the "1", and I the blank row there just doesn't show in my label, so it all works out.

Thanks for your help with this.

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.