FILL COMBOBOX WITH DICTIONARY

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

FILL COMBOBOX WITH DICTIONARY

Post by sal21 »

...

FOR I =0 TO ....

If Not MYDIC.EXISTS(COLB) Then
CCODART.AddItem UCase(COLB)
Else
MYDIC.Add UCase(COLB), I
End If

NEXT I

...

Is this a corrct code to fill the combobox with unique value?

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

Re: FILL COMBOBOX WITH DICTIONARY

Post by HansV »

I think you should use

Code: Select all

    FOR I = 0 TO ....
        If Not MYDIC.EXISTS(UCase(COLB)) Then
            CCODART.AddItem UCase(COLB)
            MYDIC.Add UCase(COLB), 1
        End If
    NEXT I
Alternatively, fill the dictionary first, the populate the combo box with the keys of the dictionary:

Code: Select all

    FOR I = 0 TO ....
        MYDIC.Add UCase(COLB), 1
    NEXT I
    CCODART.List = MYDIC.Keys
Best wishes,
Hans

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

Re: FILL COMBOBOX WITH DICTIONARY

Post by sal21 »

HansV wrote:
24 Feb 2021, 17:20
I think you should use

Code: Select all

    FOR I = 0 TO ....
        If Not MYDIC.EXISTS(UCase(COLB)) Then
            CCODART.AddItem UCase(COLB)
            MYDIC.Add UCase(COLB), 1
        End If
    NEXT I
Alternatively, fill the dictionary first, the populate the combo box with the keys of the dictionary:

Code: Select all

    FOR I = 0 TO ....
        MYDIC.Add UCase(COLB), 1
    NEXT I
    CCODART.List = MYDIC.Keys
based to limit the time, first or second option?

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

Re: FILL COMBOBOX WITH DICTIONARY

Post by HansV »

I think the second one is faster, but you won't notice it unless you are processing hundreds of thousands of records.
Best wishes,
Hans