sort array from dictionary key

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

sort array from dictionary key

Post by sal21 »

perpah posted a similar question but not found :scratch: :grin: when seraching in this lounge.

...

Dim varEntry As Variant, MIAKEY As String
For Each varEntry In DIC
'Debug.Print varEntry & " " & DIC(varEntry)
MIAKEY = varEntry & " " & DIC(varEntry)
Next varEntry

...

i need to sort this item&key...????
Perphs i need to add in temp array MIAKEY and sort it when the loop for next finished?

User avatar
HansV
Administrator
Posts: 78527
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: sort array from dictionary key

Post by HansV »

See the thread Sort dictionary items.
For a more general sorting procedure, see Collection And Dictionary Procedures on Chip Pearson's website (already mentioned in loop trought dictionary collection).
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: sort array from dictionary key

Post by sal21 »

HansV wrote:See the thread Sort dictionary items.
For a more general sorting procedure, see Collection And Dictionary Procedures on Chip Pearson's website (already mentioned in loop trought dictionary collection).
OK! sorry me for tath, now all work fine...
but a dubt. When i declare Dictionary option. Is really required this line:

DIC.CompareMode = vbTextCompare

bsed:
...
If DIC.Exists(CODICE) Then
DIC(CODICE) = DIC(CODICE) + 1
Else
DIC.Add CODICE, 1
End If
...

User avatar
HansV
Administrator
Posts: 78527
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: sort array from dictionary key

Post by HansV »

The default value of CompareMode is vbBinaryCompare. This means that string comparisons are case-sensitive: CODICE = "Sal" is different from CODICE = "sal" and from CODICE = "SAL".
If you set CompareMode to vbTextCompare, string comparisons are not case-sensitive: "sal" and "Sal" and "SAL" are seen as the same string.

Whether you want vbBinaryCompare or vbTextCompare depends on what your project requires. You have to decide.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: sort array from dictionary key

Post by sal21 »

HansV wrote:The default value of CompareMode is vbBinaryCompare. This means that string comparisons are case-sensitive: CODICE = "Sal" is different from CODICE = "sal" and from CODICE = "SAL".
If you set CompareMode to vbTextCompare, string comparisons are not case-sensitive: "sal" and "Sal" and "SAL" are seen as the same string.

Whether you want vbBinaryCompare or vbTextCompare depends on what your project requires. You have to decide.
great explain.
Tks.