scripting.dictionary

HESH

Board Regular
Joined
Mar 3, 2011
Messages
52
Hello All
I want a clear example to understand the mechanism of scripting.dictionary
I have read much about it, But the idea did not receive
Can anyone explain to me


Your help is my appreciation and my respect
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Greetings Hesh,

It may seem an odd question, but what year Excel are you using?

As to Dictionary, what parts are giving you fits? In the most general sense, I would describe it as a collection of unique keys, wherein each key has an associated defintion or value. Sort of like a two dimensional array, wherein each element of the first dimension is required to be unique. Is that making any sense?

Mark
 
Upvote 0
Thank you Mark
i am using excel from 2007
and i will try to understand every thing
just please start
 
Upvote 0
From script56.chm:
A Dictionary object is the equivalent of a PERL associative array. Items can be any form of data, and are stored in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually an integer or a string, but can be anything except an array.
 
Upvote 0
Do you have a specific application in mind or is it just curiosity?

The scripting dictionary object, as GTO says, is a container. It starts off empty and the way it's set up makes it easy to determine whether a given piece of data already exists in the container. If not, you can add it, if it does, you can increment or otherwise amend the value associated with it. This makes it very useful for quickly building up lists of unique values from otherwise duplicated data, among other things.

Why it's called "scripting dictionary", well, I have no idea. It confused the heck out of me, the first time I encountered it.
 
Upvote 0
Download the help file. It explains what is what and gives an example. Searching gives lots of examples.

Code:
Sub DicDemo()
'Early Binding method requires Reference: MicroSoft Scripting Runtime, scrrun.dll
  Dim a, i As Integer   ' Create some variables.
  Dim pos As Integer
  'Dim d As Object 'Late Binding method
  Dim s As String
  Dim d As Dictionary     'Early Binding method
  Set d = New Dictionary  'Early Binding Method
  
  'Set d = CreateObject("Scripting.Dictionary")  'Late Binding method

  d.Add "a", "Athens"   ' Add some keys and items.
  d.Add "aa", "Athens" '
   
  Rem d.Add "a", "Belgrade"    'Illegal, no duplicate keys allowed.

  d.Add "b", "Cairo"

  d.Add "c", "Belgrade"

  a = d.Items    ' Get the items.
  'a = d.Keys      ' Get the keys.
   
  For i = 0 To d.Count - 1 ' Iterate the array.
    s = s & a(i) & "<BR>" ' Return results.
  Next i

  pos = WorksheetFunction.Match("Athens", WorksheetFunction.Transpose(a), 0)
  MsgBox "Athens = position " & pos
  
  pos = WorksheetFunction.Match("cairo", WorksheetFunction.Transpose(a), 0)
  MsgBox "Cairo = position " & pos
  
  MsgBox "Item Position 1 = " & d.Items(1) & vbCrLf & _
    "Item Position 3 = " & d.Items(3)
  d.Items
  On Error Resume Next
  pos = 0
  pos = WorksheetFunction.Match("Athens, Greece", WorksheetFunction.Transpose(a), 0)
  If pos <> 0 Then
    MsgBox "Athens, Greece = position " & pos
    Else
    MsgBox "Athens, Greece = Not Found"
  End If
  
  MsgBox d.Keys(1), , d.Items(1)
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,513
Messages
6,179,214
Members
452,895
Latest member
BILLING GUY

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top