Thread: collection obj
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Matthew Herbert[_3_] Matthew Herbert[_3_] is offline
external usenet poster
 
Posts: 149
Default collection obj

Cate,

Good to hear that you were able to answer your own question. As far as
portability goes, one thing you can look into is the concept of late binding.
You can used late binding to create a Scripting Runtime object with the
following code:

Dim objDic As Object
Set objDic = CreateObject("Scripting.Dictionary")

Late binding does not require the Scripting Runtime reference to be checked.
So, the code above will behave the same as if you checked the Scripting
Runtime reference and used the following code:

Dim Dic As Scripting.Dictionary
Set Dic = New Scripting.Dictionary

(One downside, though, is that late binding does not give you the benefit of
Intellisense. However, you could create the code by checking the reference
(early binding), writing/running/testing the code in the early bound
environment, and then switch the code to late bound environment when you are
comfortable with the way that the code is behaving).

Best,

Matthew Herbert

"cate" wrote:

On Jan 31, 11:18 am, cate wrote:
I'm having some trouble with the collection obj. My first time out.
I seem can't test it.
(placing strings into what I would call a hash/dictionary. Am I doing
that?)

Dim usedFields As Collection
Set usedFields = New Collection

usedFields.Add("string); ' doesn't die

Later, I want to know if an item exists

if usedFields.Item("string")
if exists.usedFields ...
if usedFields.Item("string") < ""
if usedFields.Item("string") < 0

All get me the yellow bug line. How do test for exists?

Help. Thank you.


It's one of these - answer myself posts.

I installed a reference to Microsoft Scripting Runtime and got a
Dictionary. I don't know how this will affect the portability of the
code within the company but for now it's working just fine. Sorry for
the post.
.