The following very simple code is giving me no end of grief
Essentially, it should add every group from an single OU to a dictionary. However, I get the dreaded " This key is already associated with an element of this collection" error. It's quite patently NOT the case because there is no way two groups with the same name could exist within the same OU. If I echo out the group names there are NO duplicates. So why is the dictionary complaining?
I think that 'objGroupMemberRecordSet.Fields("name")' returns an object, that has a default property delivering a string (the name, I presume). The assignment to 'grupname' triggers that default property, while using it in a parameter list in the ''objDict.Add objGroupMemberRecordSet.Fields("name"),""' call does not.
If my assumption is correct, your problem could be used as an example for the rule
[When in doubt/Always] use the full qualified name of the property instead of relying on the defaults.
(e.g. objGroupMemberRecordSet.Fields("name").Name (or .Value, or ... I don't know anything about LDAP/ADP)
like Perl, VBScript tries to do the 'right thing' to make the programmer's life easy. Other than Perl, VBScript fails so often, that you can't rely on it.
If you do
Set oV = oX
there isn't any doubt, the object is assigned. From the missing Set in
sV = oX
VBScript knows that you don't ask for the object, so it will deliver the value of the (non object) default property (assuming there is one).
Calling a sub or function doesn't allow for an indicator like Set; so the object is passed always.
Add to this that Subs are called with no parameter list (), effectively hiding the fact of calling a procedure to all programmers familiar with decent (in that respect) C alike languages, you really are a lucky guy to not have been ambushed by this feature before.