LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default dictionary count is greater than number of keys?

Dear Group,

I am completely stumped by this. I am filling a dictionary and then
looping over an array made from its keys later. However, if I loop to
the count size of the dictionary I will hit an error. The reason seems
to be that the array that is made via the keys method, is one element
shorter than the dictionary count?

Sample code below:
Option Explicit

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
'' INPUTS HERE ''
Public Const distance As Single = 26.1
Public lrods As Dictionary
Public lrods_1 As Dictionary
Public lrods_9 As Dictionary
Public worst As Integer
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''


Sub Identify_lrods()
Dim ws As Worksheet
Dim i As Integer
Set lrods = New Dictionary
Set lrods_1 = New Dictionary
Set lrods_9 = New Dictionary

'look at sheet 3
Set ws = ThisWorkbook.Worksheets("3")
'loop through cells till empty
i = 0

Do While IsEmpty(ws.Range("J" & 3 + i)) < True

If ws.Range("P" & 3 + i) (distance / 1000) And ws.Range("B" & 3
+ i) = 1 Then _
lrods_1.Add ws.Range("J" & CStr(3 + i)), ws.Range("P" & CStr(3
+ i))

If ws.Range("P" & 3 + i) (distance / 1000) And ws.Range("B" & 3
+ i) = 9 Then _
lrods_9.Add ws.Range("J" & CStr(3 + i)), ws.Range("P" & CStr(3
+ i))

i = i + 2 'skip every second
Loop

Debug.Print "after filling dictionaries - the i value was", i - 2
Debug.Print "dictionary info", lrods_9.Count, UBound(lrods_9.Keys)

End Sub

Many thanks,
Tim
 
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
count the number of rows with entries greater than zero r2rcode Excel Worksheet Functions 1 May 17th 10 05:35 PM
Defining Variable Type for Items and Keys in Dictionary ExcelMonkey Excel Programming 5 May 4th 07 09:22 PM
Count of Number Values Greater Than, Less Than Anne Excel Worksheet Functions 6 October 12th 06 07:04 PM
count a number that is less than a number and greater than a numbe Dale Excel Worksheet Functions 3 November 19th 05 05:14 PM
dictionary keys julio Excel Programming 11 June 21st 04 08:21 PM


All times are GMT +1. The time now is 10:25 PM.

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"