Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Scripting.Dictionary problem

Back to Forum: Tech Off
  • User profile image
    Massif

    OK, so I'm working in VB6 (shudder) and I've got a major problem which I just don't understand.

    The following code always breaks:

    tempId = CStr(vlResultsRs("Id").Value)
                   
    If Not Names.Exists(tempId) Then

       tempValue = CStr(vlResultsRs("name").Value)

       'This line fails
       Call AttributeNames.Add(tempId, tempValue)

    End If

    Names is a Scripting.Dictionary object, and vlResultsRS is a recordset. tempId and tempValue are both strings.

    This is already inside some code which validates the recordset - and getting the data out of the recordset works fine. I've been able to print out all the value for tempID and tempValue and they're all as I'd expect them.

    There's a lot of repetition in the results, which is why I'm checking to see if the values already exist. Any ideas?

  • User profile image
    jensri

    The problem is the following: You're checking "Names" for the existance of the ID and afterwards trying to add the data to "AttributeNames". You simply mixed up the variable names... Big Smile

  • User profile image
    Massif

    Not so simple - I was trying to tidy up the code for posting in the question, and forgot to rename the version in the If statement.

    Good try though Smiley

  • User profile image
    vbcc


    I had a similar instance of your problem when using  .EXISTS.  Kept me up for hours, could find no real reason why .EXISTS wasnt working properly.

    every time is STEPPED through the procedure it bypassed the If..then even with a valid value.


    call someDictionary.add(sKey, sValue)

    if somedictionary.exists(skey) then

       ' do something here

    end if

    * I first thought ok make sure skey was a string.. Check!

    * stepping through STILL passed the value.  Debug Window also showed result as FALSE when manually entering in value.

    * I created list of KEYS by printing out as someDictionary.keys(iCtr).
    it cleary shows the key existing same size and all, it sounds like the two are identical problems.

    luckily this was just a tool piece of software for myself so I gave myself  two choices to replace this :

    1) Create Data string to concatenate new items, use a delimiter that will not be used as a key item, and then use instr fn on it to see if > 0.  Works OK if string is small.

    2) modified useage of INI call to give True/False return.  Create INI on fly and see if was already used.
    call readini ([ini file name], [section name], [key to search for], [value]).

    ini call returned False if NOT FOUND or NO DATA. SInce Data was not an issue, this did ok for my problem.  I am interested if you came up with a solution / fix.


Conversation locked

This conversation has been locked by the site admins. No new comments can be made.