Link to home
Start Free TrialLog in
Avatar of merydion
merydion

asked on

An interesting observation re: VB6 & Dictionaries

I use dictionaries extensively to keep track of data within the program.

In this case, I was using the dictionary to determine which records should be deleted.

Unfortunetley, all records were being deleted (test only, thank goodness!).

This is what I learned:

If you are stupid, like I was apparently, and get the sequence mixed up just a wee little  bit...

vKey = gRecord.Field("MasterKey")
sDictData = gDict.Item(vKey)
If Not gDict.Exists(vKey) Then SkipStuff
... process deletes

----------------

That code would ADD the value to the data dictionary, regardless of whether it is there or not!

vKey = gRecord.Field("MasterKey")
If Not gDict.Exists(vKey) Then SkipStuff
   sDictData = gDict.Item(vKey)
   ... process deletes

---------------

This works fine.

Thought I would share this... and perhaps,  if someone has an observation to share back, that would be equally interesting.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

This is a typical Programming Logic Error, which is quite difficult to debug if code is not commented.
please comment the code so you and others will understand it later also.
Avatar of merydion
merydion

ASKER

The code is commented, I just didn't do so here for brevity.
ASKER CERTIFIED SOLUTION
Avatar of JR2003
JR2003

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial