Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Strange dictionary behaviour

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,55478
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Strange dictionary behaviour
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Strange dictionary behaviour - 1/15/2008 7:42:00 PM   
  ginolard


Posts: 1051
Score: 21
Joined: 8/10/2005
Status: offline
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?

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm
 
 
Post #: 1
 
 RE: Strange dictionary behaviour - 1/15/2008 7:49:50 PM   
  ginolard


Posts: 1051
Score: 21
Joined: 8/10/2005
Status: offline
Ok, I don't get this.

If I change the Do Loop to the following it works


      

WTF?!

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to ginolard)
 
 
Post #: 2
 
 RE: Strange dictionary behaviour - 1/15/2008 8:05:13 PM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi ginolard,

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)

Regards

ehvbs

(in reply to ginolard)
 
 
Post #: 3
 
 RE: Strange dictionary behaviour - 1/15/2008 8:19:55 PM   
  ginolard


Posts: 1051
Score: 21
Joined: 8/10/2005
Status: offline
Yes indeed, I believe you are correct.  Adding that missing .Value is the key.  Seems unbelievable that I have not come across this issue before!

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to ehvbs)
 
 
Post #: 4
 
 RE: Strange dictionary behaviour - 1/15/2008 8:42:00 PM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi ginolard,

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.

May your luck continue!

ehvbs

(in reply to ginolard)
 
 
Post #: 5
 
 RE: Strange dictionary behaviour - 1/15/2008 8:45:03 PM   
  ginolard


Posts: 1051
Score: 21
Joined: 8/10/2005
Status: offline
Ah well, lesson learned I guess. 

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to ehvbs)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Strange dictionary behaviour Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts