Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Defining Variable Type for Items and Keys in Dictionary

In the routine below I do not have Option Explicit turned off. When I turn
it on, I get error messages telling me that "Keys" and "Items" are not
defined. What do define them as?

Sub DictionaryDemo()
Dim d as Dictionary
Dim SearchTerm As String
Dim X As Integer

Set d = CreateObject("Scripting.Dictionary")

d.Add "Rob", "Athens" ' Add some keys and items.
d.Add "Barry", "Belgrade"
d.Add "Tim", "Cairo"
d.Add "Tom", "Edmonton"
d.Add "Sue", "Calgary"
d.Add "Sherry", "Vancouver"
d.Add "Brian", "Toronto"
d.Add "Anne", "New Jersey"
d.Add "Dave", "New York"
d.Add "Rick", "Houston"

Items = d.Items
Keys = d.Keys

SearchTerm = "Rob"

Debug.Print "Arrray contains the following data:"

For X = 0 To UBound(Keys)
If Keys(X) = "Rob" Then
Debug.Print Keys(X) & ": " & Items(X)
End If
Next
End Sub

Thanks
EM
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Defining Variable Type for Items and Keys in Dictionary

Set a reference to the MS Scripting run time and see if this code helps:

Sub test()

Dim i As Long
Dim oDict As Scripting.Dictionary

Set oDict = New Scripting.Dictionary

For i = 1 To 10
oDict.Add Key:=i + 1, Item:=i
Next i

MsgBox oDict.Exists(11), , "key 11 exists?"

End Sub


RBS


"ExcelMonkey" wrote in message
...
In the routine below I do not have Option Explicit turned off. When I
turn
it on, I get error messages telling me that "Keys" and "Items" are not
defined. What do define them as?

Sub DictionaryDemo()
Dim d as Dictionary
Dim SearchTerm As String
Dim X As Integer

Set d = CreateObject("Scripting.Dictionary")

d.Add "Rob", "Athens" ' Add some keys and items.
d.Add "Barry", "Belgrade"
d.Add "Tim", "Cairo"
d.Add "Tom", "Edmonton"
d.Add "Sue", "Calgary"
d.Add "Sherry", "Vancouver"
d.Add "Brian", "Toronto"
d.Add "Anne", "New Jersey"
d.Add "Dave", "New York"
d.Add "Rick", "Houston"

Items = d.Items
Keys = d.Keys

SearchTerm = "Rob"

Debug.Print "Arrray contains the following data:"

For X = 0 To UBound(Keys)
If Keys(X) = "Rob" Then
Debug.Print Keys(X) & ": " & Items(X)
End If
Next
End Sub

Thanks
EM


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Defining Variable Type for Items and Keys in Dictionary

Hello Monkey,

Sub DictionaryDemo()
Dim d as Dictionary
Dim SearchTerm As String
Dim X As Integer
Dim Keys as Variant
Dim Items as Variant

--
Regards,
Tom Ogilvy


"ExcelMonkey" wrote:

In the routine below I do not have Option Explicit turned off. When I turn
it on, I get error messages telling me that "Keys" and "Items" are not
defined. What do define them as?

Sub DictionaryDemo()
Dim d as Dictionary
Dim SearchTerm As String
Dim X As Integer

Set d = CreateObject("Scripting.Dictionary")

d.Add "Rob", "Athens" ' Add some keys and items.
d.Add "Barry", "Belgrade"
d.Add "Tim", "Cairo"
d.Add "Tom", "Edmonton"
d.Add "Sue", "Calgary"
d.Add "Sherry", "Vancouver"
d.Add "Brian", "Toronto"
d.Add "Anne", "New Jersey"
d.Add "Dave", "New York"
d.Add "Rick", "Houston"

Items = d.Items
Keys = d.Keys

SearchTerm = "Rob"

Debug.Print "Arrray contains the following data:"

For X = 0 To UBound(Keys)
If Keys(X) = "Rob" Then
Debug.Print Keys(X) & ": " & Items(X)
End If
Next
End Sub

Thanks
EM

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Defining Variable Type for Items and Keys in Dictionary

Yes Tom they needed to be dimensioned as Variants. Wasn't sure what data
type to use. Was originaly thinking it was going to be
"Dictionary.Something" but nothing was coming up in the itellisense.

Thanks

"Tom Ogilvy" wrote:

Hello Monkey,

Sub DictionaryDemo()
Dim d as Dictionary
Dim SearchTerm As String
Dim X As Integer
Dim Keys as Variant
Dim Items as Variant

--
Regards,
Tom Ogilvy


"ExcelMonkey" wrote:

In the routine below I do not have Option Explicit turned off. When I turn
it on, I get error messages telling me that "Keys" and "Items" are not
defined. What do define them as?

Sub DictionaryDemo()
Dim d as Dictionary
Dim SearchTerm As String
Dim X As Integer

Set d = CreateObject("Scripting.Dictionary")

d.Add "Rob", "Athens" ' Add some keys and items.
d.Add "Barry", "Belgrade"
d.Add "Tim", "Cairo"
d.Add "Tom", "Edmonton"
d.Add "Sue", "Calgary"
d.Add "Sherry", "Vancouver"
d.Add "Brian", "Toronto"
d.Add "Anne", "New Jersey"
d.Add "Dave", "New York"
d.Add "Rick", "Houston"

Items = d.Items
Keys = d.Keys

SearchTerm = "Rob"

Debug.Print "Arrray contains the following data:"

For X = 0 To UBound(Keys)
If Keys(X) = "Rob" Then
Debug.Print Keys(X) & ": " & Items(X)
End If
Next
End Sub

Thanks
EM

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Defining Variable Type for Items and Keys in Dictionary

these properties are passed as arrays, so a variant is needed.

--
Regards,
Tom Ogilvy


"ExcelMonkey" wrote:

Yes Tom they needed to be dimensioned as Variants. Wasn't sure what data
type to use. Was originaly thinking it was going to be
"Dictionary.Something" but nothing was coming up in the itellisense.

Thanks

"Tom Ogilvy" wrote:

Hello Monkey,

Sub DictionaryDemo()
Dim d as Dictionary
Dim SearchTerm As String
Dim X As Integer
Dim Keys as Variant
Dim Items as Variant

--
Regards,
Tom Ogilvy


"ExcelMonkey" wrote:

In the routine below I do not have Option Explicit turned off. When I turn
it on, I get error messages telling me that "Keys" and "Items" are not
defined. What do define them as?

Sub DictionaryDemo()
Dim d as Dictionary
Dim SearchTerm As String
Dim X As Integer

Set d = CreateObject("Scripting.Dictionary")

d.Add "Rob", "Athens" ' Add some keys and items.
d.Add "Barry", "Belgrade"
d.Add "Tim", "Cairo"
d.Add "Tom", "Edmonton"
d.Add "Sue", "Calgary"
d.Add "Sherry", "Vancouver"
d.Add "Brian", "Toronto"
d.Add "Anne", "New Jersey"
d.Add "Dave", "New York"
d.Add "Rick", "Houston"

Items = d.Items
Keys = d.Keys

SearchTerm = "Rob"

Debug.Print "Arrray contains the following data:"

For X = 0 To UBound(Keys)
If Keys(X) = "Rob" Then
Debug.Print Keys(X) & ": " & Items(X)
End If
Next
End Sub

Thanks
EM



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Defining Variable Type for Items and Keys in Dictionary


Dim Items as ????????????
Dim Keys as ????????????

i think that's what it's looking for.
susan

On May 4, 1:15 pm, ExcelMonkey
wrote:
In the routine below I do not have Option Explicit turned off. When I turn
it on, I get error messages telling me that "Keys" and "Items" are not
defined. What do define them as?

Sub DictionaryDemo()
Dim d as Dictionary
Dim SearchTerm As String
Dim X As Integer

Set d = CreateObject("Scripting.Dictionary")

d.Add "Rob", "Athens" ' Add some keys and items.
d.Add "Barry", "Belgrade"
d.Add "Tim", "Cairo"
d.Add "Tom", "Edmonton"
d.Add "Sue", "Calgary"
d.Add "Sherry", "Vancouver"
d.Add "Brian", "Toronto"
d.Add "Anne", "New Jersey"
d.Add "Dave", "New York"
d.Add "Rick", "Houston"

Items = d.Items
Keys = d.Keys

SearchTerm = "Rob"

Debug.Print "Arrray contains the following data:"

For X = 0 To UBound(Keys)
If Keys(X) = "Rob" Then
Debug.Print Keys(X) & ": " & Items(X)
End If
Next
End Sub

Thanks
EM



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining a type of the cell backspace Excel Programming 1 September 7th 06 11:09 AM
looping through items in a dictionary Abe[_4_] Excel Programming 4 July 8th 06 10:39 AM
Dictionary object: Error assigning user defined data type to item Paul Urbanus Excel Programming 2 December 1st 05 04:21 AM
dictionary keys julio Excel Programming 11 June 21st 04 08:21 PM
Defining input box data type? Big Chris[_30_] Excel Programming 4 January 30th 04 04:13 PM


All times are GMT +1. The time now is 05:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"