Re: Quick one - array




"Hilton" <get_chatting@xxxxxxxxxxx> wrote in message
news:uPF6whcHHHA.3668@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

I have an array I want to populate with the count of each unique item in a
particular field. i.e the array with pick up each unique item in the field
and set it's upper limit to the number of records it picks up for each
unique item

A 100
B 150
C 200

How do I do this without having hard code the size of each item eg for i =
1
to 100, etc



Assuming your not using a SQL compliant data source where GROUP BY and COUNT
would be the appropriate solution and if you're not too fussy about using
scrrun.dll then the Scripting.Dictionary object can help eg:-

Set oDict = New Scripting.Dictionary

oDict("A") = oDict("A") + 1

oDict("B") = oDict("B") + 1

oDict("A") = oDict("A") + 1

oDict("C") = oDict("C") + 1

oDict("A") = oDict("A") + 1

oDict("B") = oDict("B") + 1

oDict("A") = oDict("A") + 1

For Each key In oDict
listbox1.AddItem key & ": " & oDict(key)
Next

Generates:-

A: 4
B: 2
C: 1

Anthony.


.



Relevant Pages

  • Re: Populate a Multi-Column ListBox
    ... It seems to me that I should somehow be able to directly populate ... ListBox column 1 with an array of state names created using the Split ... Dim myArray1 As Variant ...
    (microsoft.public.word.vba.userforms)
  • Re: Populate a Multi-Column ListBox
    ... It seems to me that I should somehow be able to directly populate ... ListBox column 1 with an array of state names created using the Split ... Dim myArray1 As Variant ...
    (microsoft.public.word.vba.userforms)
  • Re: Populate a Multi-Column ListBox
    ... two-dimensional array to load into a ListBox or ComboBox. ... For a multicolumn ListBox or ComboBox, AddItem inserts an entire row, ... If you populate a ListBox with an Array using the List of Column ... Dim myArray As Variant ...
    (microsoft.public.word.vba.userforms)
  • Re: Populate a Multi-Column ListBox
    ... two-dimensional array to load into a ListBox or ComboBox. ... For a multicolumn ListBox or ComboBox, AddItem inserts an entire row, ... If you populate a ListBox with an Array using the List of Column ... Dim myArray As Variant ...
    (microsoft.public.word.vba.userforms)
  • Re: Populate a Multi-Column ListBox
    ... two-dimensional array to load into a ListBox or ComboBox. ... For a multicolumn ListBox or ComboBox, AddItem inserts an entire row, ... If you populate a ListBox with an Array using the List of Column ... Dim myArray As Variant ...
    (microsoft.public.word.vba.userforms)